...

View Full Version : about preg_match_all statement



swethak
08-07-2008, 07:10 AM
hi,

i write a code to capture all the information in between <p> tags.But In between the <p> tags some <img> tags also there.And i write a condition as i capture all the information in between <p> tags and didn't take the img tags information.How i write the condition for that.plz help me.



<?php
$content= file_get_contents('http://www.website.com');
preg_match_all( '/<p (.*)>(.*)<\/p>/s', $content, $match, PREG_PATTERN_ORDER);

echo "<b>Capture Images :</b><br>";
echo "<br>";
print_r($match[0]);
?>



In that preg_match_all(( '/<p (.*)>(.* In that how i add the condition as not take image tags.Anybody plz give reply.

derzok
08-07-2008, 01:36 PM
It might be easier (for both you and anyone else who has to read the code) to use two separate regexps. One to match everything between the <p> tags and another to remove all the image tags (or any other tags you don't want). I'd suggest using preg_replace to replace any occurrences with an empty string.

jaap
08-09-2008, 12:31 PM
Also, when fetching content from a different site, you can trim off all whitespace by doing a preg_replace. This makes searching for your pattern easier:

$content = preg_replace('/\s\s+/',' ',$content);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum