Forum Moderators: coopster
preg_match_all(): Unknown modifier '/' blahblahblah eval()'d code on line **
for the following code:
preg_match_all("/http:\/\/scd.mm-[0-9a-z]*.yimg.com\/image\/[0-9]*/", $source, $result);
i've trade changeing to this:
preg_match_all("/http:\/\/[0-9a-z]*.mm-[0-9a-z]*.yimg.com\/image\/[0-9]*", $source, $result);
or
preg_match_all("/http:\/\/[\w]*.mm-[\w]*.yimg.com\/image\/[\d]*", $source, $result);
but still get an error.
any suggesstions?
Also, I don't know if this is anything, but you have your regular expression declared inside double quotes. I've always avoided doing that, as it was unclear to me if the regular expression engine would see the following
preg_match("/\\n/") as a newline, or as a literal \n, since strings require escaping and then the regular expression engine require escaping. I always use single quotes instead, giving me one less thing to have to think about during debugging.
preg_match('/\n/') Hope that helps.
So
echo 'You are in \/usr\/bin';
// output: You are in /usr/bin;
echo 'You are in /usr/bin';
// output: You are in /usr/bin;
YOU WANT
echo 'You are in \\/usr\\/bin';
// output: You are in \/usr\/bin;
because you want the \/ sequence to get sent to the regex engine
There is, however, and easier way around the whole thing. You can use most any delimiter you want with the preg* functions, so here's a good time to use something like a back tick or a hash mark or whatever so you don't have to escape the slashes at all
$pattern = '`/http://scd.mm-[0-9a-z]*.yimg.com/image/[0-9]*`';
$pattern = '#/http://scd.mm-[0-9a-z]*.yimg.com/image/[0-9]*#';