how to extract this text ?

Discussion in 'PHP' started by ramysarwat, Sep 20, 2010.

  1. #1
    how can i extract "123 abc" from this text ?

    <p class="test">some text<font style="color:#1E9A9F;">| 123 abc</font></p>
     
    ramysarwat, Sep 20, 2010 IP
  2. Kakers

    Kakers Active Member

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #2
    Well I don't know of any way you could extract that certain bit of text exactly but you could either user striptags which would return "some text| 123 abc" if you echoed it or if your looking to see if 123 abc exists in that string of text, then it is fairly easy using strpos which will return true or false. You could then use that to do whatever you want.
     
    Kakers, Sep 20, 2010 IP
  3. gio

    gio Well-Known Member

    Messages:
    2,390
    Likes Received:
    162
    Best Answers:
    0
    Trophy Points:
    195
    #3
    try this one:

    <?php
    $content = '<p class="test">some text<font style="color:#1E9A9F;">| 123 abc</font></p>';
    $find_this = '/<p class="test">some text<font style="color:#1E9A9F;">\| (.*)<\/font><\/p>/';
    
    if (preg_match($find_this, $content, $matches)) {
    	echo $matches[1];
    }
    ?>
    
    PHP:
     
    gio, Sep 20, 2010 IP
  4. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    you can use preg_match as Gio stated above.
    And i think his code will work.
     
    ivan.kristianto, Sep 20, 2010 IP
  5. RandyCram

    RandyCram Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    gio posted what i know of as the best method to do what you are asking.
     
    RandyCram, Sep 20, 2010 IP
  6. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    #6
    yes, GEO is right
     
    ashishkg, Sep 21, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    preg_match('~<p class="test">some text<font style="color:#1E9A9F;">\| ([^<]+)</font></p>~', $text, $output);
    
    echo $output[1];
    PHP:
     
    danx10, Sep 21, 2010 IP