Need Help In Php Fetching

Discussion in 'PHP' started by Bohra, Jun 4, 2009.

  1. #1
    Well I Need help in fetching a part of some external code

    For example

    <div class="test">Some text here</div>

    i want to fetch the Some text here part only

    How i can i do this please help me with a small code

    Thanks
     
    Bohra, Jun 4, 2009 IP
  2. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #2
    Fetch text from where , the code will depend on that .
     
    it career, Jun 4, 2009 IP
    Bohra likes this.
  3. givemeknol

    givemeknol Active Member

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #3
    givemeknol, Jun 4, 2009 IP
    Bohra likes this.
  4. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #4
    From a external site
     
    Bohra, Jun 4, 2009 IP
  5. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here you go just change the $fetchedata to grab data from a website.
    
    <?php
    
    $fetchedata = '<div class="test">Some text here</div>';
    preg_match('/<div class="test">(.*?)<\/div>/is', $fetchedata, $matches);
    echo $matches[1];
    
    ?>
    
    PHP:
     
    atlantaazfinest, Jun 4, 2009 IP
  6. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So ideally you probably would do and change

    <div class="test">(.*?)<\/div>
    Code (markup):
    to the code you want to grab and put (.*?) in the place of the information you want to grab. hope you understand .

    
    <?php
    
    $fetchedata = file_get_contents("http://website.com");
    preg_match('/<div class="test">(.*?)<\/div>/is', $fetchedata, $matches);
    echo $matches[1];
    
    ?>
    
    PHP:
     
    atlantaazfinest, Jun 4, 2009 IP
    Bohra likes this.
  7. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #7
    Edit

    So i have finally got what i wanted thanks a lot all

    Green rep to all for helping :)
     
    Bohra, Jun 4, 2009 IP