Other php code for get content

Status
Not open for further replies.
2 comments
there are multiple way to scrape/fetch content from source code of a website.

You can use "regex", strstr, libxml even explod.

I love to use LibXML its easy, fast and let you get what you want without wasting time...


PHP:
libxml_use_internal_errors(true);        
$html = file_get_contents('://website.com/pagesourcetofetch.html');        
$dom = new domDocument;        
@$dom->loadHTML($html);       
 $dom->preserveWhiteSpace = false;        
$xpath = new DOMXPath($dom); 
 $blekk = $xpath->query("//div[contains(@class,'pagetitle')]/h1");         
foreach($blekk as $index => $row) {             
 $title =$row->nodeValue;       
  }

//div <-- you have to tell it its a "DIV" tag if you want to fetch inside "div", even you could use "p", "span" etc..
[contains(@class,'pagetitle') <-- You tell the script to find the DIV where its class is "pagetitle" (or any class).
/h1 <--- You tell the script to find "h1" tag inside the "DIV" tag.

PHP:
foreach($blekk as $index => $row){          
    $title =$row->nodeValue;       
  }

$row->nodeValue; <-- You tell the script that fetch "h1" text only;.

Thanks,
 
Not sure if I get your question correctly but if want to fetch php code, this is not possible. Only the webserver (ex. Apache) can read a php file and it will not give you its source code.
 
Status
Not open for further replies.
Back
Top