how to get certain content from a file?

Discussion in 'PHP' started by feelexit, Jul 14, 2007.

  1. #1
    I use file_get_contents to get file http://mydomain.com/test.html

    inside the html file, I need to get the text between <div id="testing"></div>

    <div id="testing">

    I need to find out whatever the content here.

    /sldfksf
    /n
    likllsdf
    </div>

    whats the best way to do it? all i can think about is to read line by line,but I got I have alot pages to process, that will take forever, is there a better way to do it.
     
    feelexit, Jul 14, 2007 IP
  2. Bishop81

    Bishop81 Peon

    Messages:
    757
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What I would do is this, assuming that you only have "<div id="testing"></div>" once in your html file...
    assuming your file is read into the variable $htmlcontents
    
    $pos1=strpos($htmlcontents, "<div id=\"testing\">");
    $pos1=$pos1+18;
    $pos2=strpos($htmlcontents, "</div>", $pos1);
    $testingvalue=substr($htmlcontents, $pos1, $pos2-$pos1);
    
    Code (markup):
    I can't say if that's the best way to do it, but that's what I would do.
     
    Bishop81, Jul 14, 2007 IP