regular expression help in php

Discussion in 'PHP' started by pozer, Nov 7, 2007.

  1. #1
    I'm trying to get a text from webpage with regular expression, text is in this form

    
    <h1><a href="url1">title1</a></h1>
    <em>something</em>
    <p>Here is some text #1
    multiline</p>
    <p>
    <div class="details"><a href="url1">more...</a></div>
    </p>
    
    <h1><a href="url2">title2</a></h1>
    <em>something</em>
    <p>Here is some text #2
    multiline</p>
    <p>
    <div class="details"><a href="url2">more...</a></div>
    </p>
    HTML:
    I tried to match this code:
    '/<h1><a href="(.*)">(.*)<\/a><\/h1>\s+<em>(.*)<\/em>\s+<p>[COLOR="Red"][B]((.|\n)*<\/p>)[/B][/COLOR]\s+<p>\s+<div class="details"><a href="(.*)">more...<\/a><\/div>\s+<\/p>/'
    Code (markup):
    but this part ((.|\n)*<\/p>) matches everything from <p> in first article all the way to </p> in the last article, but I want to grab only text:
    Here is some text #1
    multiline


    Can somebody help me please
     
    pozer, Nov 7, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Add the ungreedy pattern modifier (U).

    /PATTERN/U

    Peace,
     
    Barti1987, Nov 7, 2007 IP
    pozer likes this.