Reputation: 7053
I have got this code:
$subject=<<<EOD
<object height="400" width="500"><param name="allowfullscreen" value="false">
<param name="AllowScriptAccess" value="always">
<param name="movie" value="http://embed.rede.com/player/">
<param name="FlashVars" value="id=97219&style=reube&autostart=false">
<embed src="http://embed.rube" allowfullscreen="false" AllowScriptAccess="always"
flashvars="autostart=false" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash" height="400" width="500" /></object>
EOD;
I am trying to get all the object tags on the page with php regex:
$pattern="/<object(.*)object>/i";
preg_match_all($pattern, $subject, $matches ,PREG_PATTERN_ORDER);
echo "<br/><br/><br/><br/><br/><br/><br/><br/>";
print_r($matches);
But it retrieves nothing. I am not interested in what is inside the paranthesis.. i want to get the whole object tag. Note: I am not scraping. My input is actually a string with a few tags in it (it is users post). The question is why it doesnt retrieve me anything?!?
UPDATE .
This is where the solution was:
s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
Upvotes: 0
Views: 68
Reputation: 63
Better Regex for matching this tag is:
'~<object[^>]*>(.+)</object>~ismU'
Upvotes: 1
Reputation: 4043
danneth is right that your initial tag won't be read. It's also possible that you did not indicate that your regular expression is multiline, which is why it would stop at the first line and not proceed (dot all is single line by default IIRC).
"/<object.*?>(.+?)<\/object>/is"
Upvotes: 3