file_get_contents doubt need help

Discussion in 'PHP' started by Bohra, Jan 18, 2009.

  1. #1
    ok so can some one help me with a code

    i know how to use file_get_contents()

    but i need help to display only a particular data from the url i want to get the data from


    say something like this

    <div id=test>30</div>
    Code (markup):
    i want to pull the 30 out of the url only and not the other data
     
    Bohra, Jan 18, 2009 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    You can use preg_match, or you can use my own function below.

    
    // Usage
    $data = file_get_contents('...');
    $string = between('<div id=test>', '</div>', $data);
    
    function between($start, $end, $source) {
            $s = strpos($source, $start) + strlen($start);
            return substr($source, $s, strpos($source, $end, $s) - $s);
    }
    
    PHP:
     
    Kaizoku, Jan 19, 2009 IP
  3. riya_senk

    riya_senk Well-Known Member

    Messages:
    2,014
    Likes Received:
    174
    Best Answers:
    0
    Trophy Points:
    160
    #3
    riya_senk, Jan 19, 2009 IP
    Smyrl likes this.
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    Thanks a lot ... works like a charm
     
    Bohra, Jan 19, 2009 IP