CodeIgniter Forums
Extract body using regular expression - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Extract body using regular expression (/showthread.php?tid=5989)



Extract body using regular expression - El Forum - 02-11-2008

[eluser]Dsyfa[/eluser]
Hi,

I'm trying to extract the body of a view file using regular expression but it doesn't work.
Code:
$body = $this->load->view( 'newsFeed', '', true );
$regex = "@\<body\>(.*?)\</body\>@i";
$matches = array();
preg_match ( $regex, $body, $matches );
print_r( $matches );
The view file is basically simple:
Code:
<html>
<head>
    <title>Hello</title>
</head>
<body>
    Hello World!
</body>
</html>



Extract body using regular expression - El Forum - 02-11-2008

[eluser]Seppo[/eluser]
Try this:
Code:
$regex = "@\<body\>(.*?)\</body\>@is";

If I'm not wrong, you have to use "s" flag so . includes the new line character


Extract body using regular expression - El Forum - 02-13-2008

[eluser]Dsyfa[/eluser]
Thanks mate! It works now!