Welcome Guest, Not a member yet? Register   Sign In
Extract body using regular expression
#1

[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>
#2

[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
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB