Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    about preg_match_all statement

    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 Code:
    <?php
    $content
    file_get_contents('http://www.website.com'); 
    preg_match_all'/<p (.*)>(.*)<\/p>/s'$content$matchPREG_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.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    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.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    New Coder
    Join Date
    Aug 2005
    Location
    Groningen, Netherlands
    Posts
    57
    Thanks
    0
    Thanked 6 Times in 6 Posts
    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:
    Code:
    $content = preg_replace('/\s\s+/',' ',$content);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •