Jump to content

[SOLVED] trying to match complicated? text


DJphp

Recommended Posts

 

Hi,

 

I am successfully scraping URL's from web pages to create an RSS feed.

But, now I need to grab the first post from each link found.

I can do this successfully, except I am having some trouble with some regexp.

 

The text I receive looks like:

<!-- message -->

 

  <div class="idview"> Some text to capture

and more text.

  <div style="margin:20px; margin-top:5px; ">

some more text

  <div>

more text

/div>

And Even More TEXT !  where the ! stops the regexp

 

<!-- / message -->

 

 

 

I need to capture everything between the tags:

<!-- message -->

and

<!-- / message -->

 

 

My initial Regexp looks like:

$patternDescriptions = "/(<!-- message -->[^!]+).*/i";

 

but if there is an exclamation in the text I need then the pattern matching stops and I lose tex

 

Any help to grab all of the text between the message tags would be appreciated.

 

thanks,

DJphp

 

Link to comment
https://forums.phpfreaks.com/topic/79885-solved-trying-to-match-complicated-text/
Share on other sites

Keep it simple man...

 

<?php

$data = <<<DATA
<!-- message -->

  <div class="idview"> Some text to capture
and more text.
   <div style="margin:20px; margin-top:5px; ">
some more text
  <div>
more text
/div>
And Even More TEXT !  where the ! stops the regexp

<!-- / message -->
DATA;

preg_match("/<!-- message -->(.*?)<!-- \/ message -->/is", $data, $match);
echo $match[1];

?>

 

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.