Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

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>
0
paries
Asked:
paries
  • 2
1 Solution
 
pariesAuthor Commented:
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);
0
 
BatalfCommented:
Put in the multiline flag

preg_match("/<style.+?>/si",$contents, $tag_contents);
0
 
BatalfCommented:
Sorry, didn't see your last comment
0
 
PAQ_ManCommented:
Question Closed, 500 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now