Regular expression not quite there, need help!

Posted on 2009-07-04
Last Modified: 2012-05-07

I'm trying to take out the content between the following tags in an RSS document:

<description>Content here </description>

My code is included below which outputs the matches however I get the following at the beginning of each line..


so the line looks like

on> Some RSS content
on> Some more RSS content

So it's obviously not quite right.  Please help

$pattern = '/<description>(.*?)<\/description>/';
preg_match_all($pattern, $buffer, $matches);
foreach ($matches[0] as $val) {
	$val = substr($val, 10);
	echo "$val <br>";

Open in new window

Question by:nickmarshall
LVL 13

Expert Comment

ID: 24777224
$pattern = '/<description>([^<]*)<\/description>/';

Accepted Solution

fcardinaux earned 500 total points
ID: 24777227
The subpattern defined by your parentheses isn't in $machtes[0], but in $matches[1]:

$pattern = '/<description>(.*?)<\/description>/';
preg_match_all($pattern, $buffer, $matches);
foreach ($matches[1] as $val) {
        echo "$val <br>";

Open in new window


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

Suggested Solutions

Title # Comments Views Activity
how can i gnupg encrypt a PDF document? 12 66
Google Maps API and PHP 25 50
PHP Warning:  mysqli_real_escape_string() expects exactly 2 parameters 4 26
Ahax pagination 9 34
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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