Solved

Regular expression not quite there, need help!

Posted on 2009-07-04
2
326 Views
Last Modified: 2012-05-07
Experts,

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

on>

so the line looks like

on> Some RSS content
on> Some more RSS content

So it's obviously not quite right.  Please help

on>
<?php
 

$pattern = '/<description>(.*?)<\/description>/';
 

preg_match_all($pattern, $buffer, $matches);

//print_r($regMatches);
 

foreach ($matches[0] as $val) {

	$val = substr($val, 10);

	echo "$val <br>";

}
 

?>

Open in new window

0
Comment
Question by:nickmarshall
2 Comments
 
LVL 13

Expert Comment

by:marchent
Comment Utility
$pattern = '/<description>([^<]*)<\/description>/';
0
 
LVL 8

Accepted Solution

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

<?php

 

$pattern = '/<description>(.*?)<\/description>/';

 

preg_match_all($pattern, $buffer, $matches);

//print_r($regMatches);

 

foreach ($matches[1] as $val) {

        echo "$val <br>";

}

 

?>

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
The viewer will learn how to dynamically set the form action using jQuery.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now