比较 MySQL 中的两个字符串
我当前的查询(不起作用)
SELECT url
FROM table
WHERE
'http://www.longurl.com/some/string' like '%' . url . '%'
表
url
longurl.com
我试图将 longurl.com 的“表”中的记录与包含 longurl.com 的任何比较 URL 进行匹配。
应该匹配比较的 URL,例如:
http://www.longurl.com/some/string
http://longurl.com
http://longurl.com/some/string
在这个 PHP 示例中,比较很容易:
$url = "http://www.longurl.com/some/string";
if(strstr($url, 'longurl.com')) {
echo "success";
} else {
echo "failure";
}
My current query (doesn't work)
SELECT url
FROM table
WHERE
'http://www.longurl.com/some/string' like '%' . url . '%'
table
url
longurl.com
I am trying to match the record in "table" for longurl.com to any compared URL that contains longurl.com.
Should match compared URLs such as:
http://www.longurl.com/some/string
http://longurl.com
http://longurl.com/some/string
In this PHP example, it is very easy to compare:
$url = "http://www.longurl.com/some/string";
if(strstr($url, 'longurl.com')) {
echo "success";
} else {
echo "failure";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
好吧,怎么样:(
评论中格式不太好,所以我再次添加它作为答案。)
Okay, what about:
(Formatting didn't work so well in the comments, so I added it again as an answer.)
如果您需要获取包含
longurl.com
的所有 URL,请尝试使用:它应该可以工作。
If what you need is getting all URLs containing
longurl.com
then try using:It should work.
尝试删除或转义 URL 字符串中的某些字符。或者省略 http: 部分..我相信
:
可能会混淆解析器...甚至
甚至
Try removing or escaping some of the characters in your URL string. OR omitting the http: part .. I believe the
:
could be confusing the parser ...or even
or even
这?
或者您也可以使用%longurl.com%
this?
or you can also use %longurl.com%
MySQL 中不存在连接运算符
.
,您必须使用 CONCAT() 函数改为:The concatenation operator
.
does not exist in MySQL, you have to use the CONCAT() function instead:怎么样:
或者,就像你的 PHP 一样:
What about this:
or, to be just like your PHP:
您是否在寻找:
Are you looking for: