I have this string:
<a href="http://prodigy.msn.com/">
<a href="http://sympatico.msn.ca">
<a href="http://web.archive.org/web/199612210104 ... SoHo/9120/">
<a href="http://web.archive.org/web/199612301933 ... 20,00.html">
<a href="http://webtrends.about.com/od/profi3/p/ ... ft-bio.htm">
<a href="http://www.alexa.com/data/details/main/MSN.com">
and $variable = 'msn.com';
I want to get just the url's which have $variable inside.
Any help would be great appreciated.
Help with this regex
Moderator: General Moderators
-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Help with this regex
Assuming that is the only format you will see:
Code: Select all
$variable = 'msn.com';
preg_match_all('#href="(http://[^\.]*\.?' . preg_quote($variable, '#') . '[^"]*)"#', $input, $matches);
print_r($matches[1]);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.