I’m a newbie with regular expressions and i need some help :).
I have this:
$url = '<img src="http://mi.url.com/iconos/oks/milan.gif" alt="Milan">';
$pattern = '/<img src="http:\/\/mi.url.com/iconos/oks/(.*)" alt="(.*)"\>/i';
preg_match_all($pattern, $url, $matches);
print_r($matches);
And I get this error:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier ‘c’
I want to select that ‘milan.gif’.
How can I do that?
If you’re using
/as delimiter, you need to escape every occurrence of that character inside the regular expression. You didn’t:Here the marked
/is treated as end delimiter of the regular expression and everything after is is treated as modifier.iis a valid modifier butcisn’t (see your error message).So:
But as Pekka already noted in the comments, you shouldn’t try to use regular expressions on a non-regular language like HTML. Use an HTML parser instead. Take a look at Best methods to parse HTML.