extracting data between <td></td> tags

Discussion in 'PHP' started by linkinpark2014, Jul 16, 2008.

  1. #1
    hey guyz I want to get the content between

    <td style="border-top: 1px solid black;">bla bla bla</td>


    i used this pattern but it always gives me the whole page with <td:
    :confused:
    if(preg_match_all('/(<td style=\"border-top: 1px solid black;\">(.*)<\/td>)/'
    Code (markup):
    it should give me bla bla bla...any ideas?:rolleyes:
     
    linkinpark2014, Jul 16, 2008 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use (.*?) instead of (.*)
     
    matthewrobertbell, Jul 16, 2008 IP
  3. qprojects

    qprojects Peon

    Messages:
    1,901
    Likes Received:
    103
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try
    It should work.
    Edit: matthewrobertbell you were faster than me ;)
     
    qprojects, Jul 16, 2008 IP
  4. linkinpark2014

    linkinpark2014 Peon

    Messages:
    153
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thax man appreciated worx like charm :)
     
    linkinpark2014, Jul 16, 2008 IP
  5. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5
    The easy way to do this with explode the str.
    <?
    $page=file_get_contents('http://centralops.net/co/DomainDossier.aspx');
    $a=explode('<td valign=bottom>',$page);
    for($i=1;$i<count($a);$i++){
    $b=explode('</td>',$a[$i]);
    echo $b[0].'<br>';
    }

    ?>
     
    sastro, Jul 16, 2008 IP
  6. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #6
    preg_match_all is a lot better, regular expressions are very powerful. You have 4 line of code compared to one ;)
     
    matthewrobertbell, Jul 16, 2008 IP