Link to home
Start Free TrialLog in
Avatar of paries
paries

asked on

help with preg_match and getting info between tags spanning lines

Hello,
I am trying to get content between two tags.
I read in the contents of a html file into $contents.

I can do it ok for this eg:
<title>this is a test</title>
preg_match("/<title>(.*)<\/title>/i",$contents, $tag_contents);
the above works as i want.

My problem is i am trying to get the contents of a style block from a html file that i have read in.
the block of style looks code below::
preg_match("/<style.+?>(.*)<\/style>/i",$contents, $tag_contents);
The above snippet does not work..

The below just gives me the first line
preg_match("/<style.+?>/i",$contents, $tag_contents);

<style type="text/css">
<!--
.ft0{font-style:normal;font-weight:normal;font-size:16px;font-family:Times New Roman;color:#000000;}
.ft1{font-style:italic;font-weight:bold;font-size:27px;font-family:Times New Roman;color:#ff00ff;}
.ft2{font-style:normal;font-weight:normal;font-size:27px;font-family:Times New Roman;color:#000000;}
.ft3{font-style:normal;font-weight:normal;font-size:13px;font-family:Arial;color:#000000;}
.ft4{font-style:normal;font-weight:bold;font-size:13px;font-family:Arial;color:#000000;}
.ft5{font-style:italic;font-weight:normal;font-size:66px;font-family:NuptialScript;color:#000000;}
.ft6{font-style:italic;font-weight:normal;font-size:50px;font-family:NuptialScript;color:#000000;}
-->
</style>
Avatar of paries
paries

ASKER

ah...

Mulitline was the keyword i was missing

so i found it myself, i needed the s
preg_match("/<style.+?>(.*)<\/style>/s",$contents, $tag_contents);
Put in the multiline flag

preg_match("/<style.+?>/si",$contents, $tag_contents);
Sorry, didn't see your last comment
ASKER CERTIFIED SOLUTION
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial