hi,
I have a problem with preg_match function returning empty arrays for my wonderful regexes. However, I can't see what I am doing wrong - maybe one of you could help?
I'm loading the source of a website into variable and then using preg_match_all to extract all occurrences of a string.
it looks like this (where source code is loaded into $page variable):[code=php]
preg_match ('/<div\s+?id="srN um_\d+?"\s+?cla ss="number">(.* ?)<\/div>/', $page, $results);[/code]
a sample string which should be matched by the above is:[code=hml]
<div id="srNum_0" class="number"> 1.</div>[/code]
Funny that preg_match_all also doesn't work if I give a direct regex to match the line above:[code=php]
preg_match_all ('/<div id="srNum_0" class="number"> 1\.<\/div>/', $page, $results);[/code]
On the other hand this one works fine:[code=php]
preg_match_all ('/<title>(.*?)< \/title>/',$page, $results);[/code]
Tried hard to find the answer, to add backslashes, change single quotes to double quotes etc.
Can you see a mistake? Should any characters be escaped?
cheers
I have a problem with preg_match function returning empty arrays for my wonderful regexes. However, I can't see what I am doing wrong - maybe one of you could help?
I'm loading the source of a website into variable and then using preg_match_all to extract all occurrences of a string.
it looks like this (where source code is loaded into $page variable):[code=php]
preg_match ('/<div\s+?id="srN um_\d+?"\s+?cla ss="number">(.* ?)<\/div>/', $page, $results);[/code]
a sample string which should be matched by the above is:[code=hml]
<div id="srNum_0" class="number"> 1.</div>[/code]
Funny that preg_match_all also doesn't work if I give a direct regex to match the line above:[code=php]
preg_match_all ('/<div id="srNum_0" class="number"> 1\.<\/div>/', $page, $results);[/code]
On the other hand this one works fine:[code=php]
preg_match_all ('/<title>(.*?)< \/title>/',$page, $results);[/code]
Tried hard to find the answer, to add backslashes, change single quotes to double quotes etc.
Can you see a mistake? Should any characters be escaped?
cheers
Comment