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",$conte nts, $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;fon t-weight:n ormal;font -size:16px ;font-fami ly:Times New Roman;color:#000000;}
.ft1{font-style:italic;fon t-weight:b old;font-s ize:27px;f ont-family :Times New Roman;color:#ff00ff;}
.ft2{font-style:normal;fon t-weight:n ormal;font -size:27px ;font-fami ly:Times New Roman;color:#000000;}
.ft3{font-style:normal;fon t-weight:n ormal;font -size:13px ;font-fami ly:Arial;c olor:#0000 00;}
.ft4{font-style:normal;fon t-weight:b old;font-s ize:13px;f ont-family :Arial;col or:#000000 ;}
.ft5{font-style:italic;fon t-weight:n ormal;font -size:66px ;font-fami ly:Nuptial Script;col or:#000000 ;}
.ft6{font-style:italic;fon t-weight:n ormal;font -size:50px ;font-fami ly:Nuptial Script;col or:#000000 ;}
-->
</style>
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>(.*)<\
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.+?>(.*
The above snippet does not work..
The below just gives me the first line
preg_match("/<style.+?>/i"
<style type="text/css">
<!--
.ft0{font-style:normal;fon
.ft1{font-style:italic;fon
.ft2{font-style:normal;fon
.ft3{font-style:normal;fon
.ft4{font-style:normal;fon
.ft5{font-style:italic;fon
.ft6{font-style:italic;fon
-->
</style>
Put in the multiline flag
preg_match("/<style.+?>/si ",$content s, $tag_contents);
preg_match("/<style.+?>/si
Sorry, didn't see your last comment
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mulitline was the keyword i was missing
so i found it myself, i needed the s
preg_match("/<style.+?>(.*