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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.