views:

30

answers:

4

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 !

+2  A: 

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);
tinifni
A: 

Your regular expression needs to be escaped correctly.

It should be:

'/<a href="\/download.php\?g=(?P<number>.+)">Click here<\/a>/'
Ben Rowe
Actually it should be: `'/<a href="\/download\.php\?g=(?P<number>.+)">Click here<\/a>/'`. You forgot to escape the "." in "download.php"
Lucho
+1  A: 

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);
amphetamachine
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);
kindall