Unable to retrieve information between body tags...

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Unable to retrieve information between body tags...

Post by raghavan20 »

I am trying to get the information between body tags but I could not...

Code: Select all

<?php
$input = <<<EOD
<body>
	<b>hi all</b>
</body>
EOD;
echo preg_match_all("/<body>(.*?)<\/body>/mi", $input, $matches)."<br />";
print_r($matches);
?>
</pre>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you want mode s not mode m. m stops at ends of lines, s does not.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I used 'm' because it allows to read multiple lines as per manual...but I still do not understand how this 's' makes this regex work... :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

m requires it to be on a single line, s does not.
Post Reply