开发者

php regex error, unknown modifier 'd' [duplicate]

This question already has answers here: Warning: preg_replace(): Unknown modifier (开发者_开发问答3 answers) Closed 3 years ago.

Im trying to search for something on a page but i keep getting this silly error

this is the error i am getting

Warning: preg_match() [function.preg-match]: Unknown modifier 'd'

this is the code im using

$qa = file_get_contents($_GET['url']);
preg_match('/<a href="/download.php\?g=(?P<number>.+)">Click here</a>/',$qa,$result);

And $_GET['url'] can eqaul many things but in one case it was http://freegamesforyourwebsite.com/game/18-wheeler--2.html

the the html of that url basically

Anyone got a clue :S ? I dont even know where to start cus i dont know what a modifire is and the php.net site is no help

thankyou !


You need to escape the '/' before download.php otherwise it thinks you are ending your regex and providing 'd' as a modifier for your regex. You will also need to escape the next '/' in the ending anchor tag.

preg_match('/<a href="\/download.php\?g=(?P<number>.+)">Click here<\/a>/',$qa,$result);


You have to escape your pattern delimiters or use different ones:

#                     v- escape the '/'
preg_match('/<a href="\/download.php\?g=(?P<number>.+)">Click here</a>/',$qa,$result);

#           v- use hatch marks instead
preg_match('#<a href="/download.php\?g=(?P<number>.+)">Click here</a>#',$qa,$result);


Your regular expression needs to be escaped correctly.

It should be:

'/<a href="\/download.php\?g=(?P<number>.+)">Click here<\/a>/'


The problem is that your regular expression is delimited by / characters, but also contains / characters as data. What it's complaining about is /download -- it thinks the / has ended your regular expression and the d that follows is a modifier for your regular expression. However, there is no such modifier d.

The easiest solution is to use some character that is not contained in the regex to delimit it. In this case, @ would work well.

preg_match('@<a href="/download.php\?g=(?P<number>.+)">Click here</a>@',$qa,$result);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜