What i am trying to do is get the document title from body using DOMDocument
e-g "document_title":"iOS Programming Nuts and bolts",
The result of this code is that I get a null value on $doc_name variable.. I want the result to be "iOS Programming Nuts and bolts"
Edit : I'm trying to get json data from html source (e.g : document_description , document_title etc..)
Source code:
this is so far i have
Please help friends..
<?php
$doc_url = "https://www.scribd.com/book/281016724/iOS-Programming-Nuts-and-bolts";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$doc_url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http=="200") {
$doc = new DOMDocument();
$doc->loadHTML(htmlspecialchars($result));
$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script[@type="text/javascript"]')->item(0)->nodeValue;
$start = strpos($js, '{');
$end = strrpos($js, '),');
$json = substr($js, $start, $end - $start);
$data = json_decode($json, true);
$doc_name = $data["document_title"];
}
else
{
echo "ERROR";
}
?>