View Full Version : about preg_match_all statement

08-07-2008, 08:10 AM

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.

$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>";

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

08-07-2008, 02: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.

08-09-2008, 01: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);