Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Regular expression not quite there, need help!

Posted on 2009-07-04
2
Medium Priority
?
336 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …
Suggested Courses

650 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