Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
-
raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
-
Contact:
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>
-
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.
-
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...

-
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.