help with preg_match and getting info between tags spanning lines

Posted on 2005-03-21
Medium Priority
Last Modified: 2012-05-05
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;}
Question by:paries
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 13595469

Mulitline was the keyword i was missing

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

Expert Comment

ID: 13595723
Put in the multiline flag

preg_match("/<style.+?>/si",$contents, $tag_contents);
LVL 32

Expert Comment

ID: 13595727
Sorry, didn't see your last comment

Accepted Solution

PAQ_Man earned 0 total points
ID: 13635949
Question Closed, 500 points refunded.
Community Support Moderator

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question