?
Solved

Regular expression not quite there, need help!

Posted on 2009-07-04
2
Medium Priority
?
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Expert Comment

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

Accepted Solution

by:
fcardinaux earned 2000 total points
ID: 24777227
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 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