开发者

MySQL: search by host name in field containing urls

I have this database table:

id  | url
-----------------------------------------
1   | http://stackoverflow.com/
2   | http://www.google.com
3   | http://exampl开发者_如何学编程e.com/somepage
4   | https://another.net?id=88
5   | http://hello.org/index.php?hello=2
6   | http://google.com?q=hello+world

I need to search all fields, where URL belongs to a certain host.

For example, if I give the query 'google.com', it will return rows 2 and 6 (www is ignored). I get the host using PHP parse_url() function.

How this SQL query would look like?


SELECT * FROM table_name WHERE url like '%host_name%'

Replace table_name with the name of your table and replace host_name with the name of the host you are looking for to be contained in the url.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜