help with some pattern

Discussion in 'PHP' started by catapop, Nov 27, 2008.

  1. #1
    hi. I have a little problem. I'm trying to parse data from a site and I need some help.

    I have a simililar html structure

    <div>some content</div>
    Code (markup):
    and
    <div><p>some content</p></div>
    Code (markup):
    What is the pattern so i can grabb some content if sometimes is between <p> tag and sometimes is not

    Thx
     
    catapop, Nov 27, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    what function are you using when grabbing the content?
    ill start with your function
     
    bartolay13, Nov 27, 2008 IP
  3. catapop

    catapop Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    preg_match_all but i only need the pattern(regexp) parameter
     
    catapop, Nov 27, 2008 IP
  4. peeeev

    peeeev Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    $c = "<div>some content</div>";
    $c .= "<div><p>some content</p></div>";
    
    preg_match_all( '/<div>(?:<p>)?(.*?)(?:<\/p>)?<\/div>/ims', $c, $m);
    
    print_r($m[1]);
    
    PHP:
    Will output:

    Array
    (
    [0] => some content
    [1] => some content
    )
     
    peeeev, Nov 28, 2008 IP
  5. catapop

    catapop Peon

    Messages:
    79
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    works fine. thx.
     
    catapop, Nov 28, 2008 IP