943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1073
  • PHP RSS
Sep 3rd, 2010
0

Using preg_match to grab content between tags

Expand Post »
Hello people,

I'm trying to collect some data stored between <body> and </body> tags inside a string.

Here's a piece of the code i'm using:

PHP Syntax (Toggle Plain Text)
  1. $regex = '/<body>(.*?)<\/body>/si';
  2. preg_match($regex, $content, $content);
  3. $content = $content[0];

This works perfect, except that it also includes the above mentioned tags. I would just like to grab the content in between those tags and store it.

In other words, only store the (.*?) part of the regex.

Anyone have an idea how to solve this?
Last edited by macdonald12; Sep 3rd, 2010 at 6:43 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
macdonald12 is offline Offline
9 posts
since Sep 2009
Sep 3rd, 2010
0
Re: Using preg_match to grab content between tags
*Sigh*

Got it. Using $content[1] does the trick
Reputation Points: 10
Solved Threads: 0
Newbie Poster
macdonald12 is offline Offline
9 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php with database help
Next Thread in PHP Forum Timeline: Select to send my form to different emails





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC