Reputation: 11
I'm new here and a recent user of php. I have this problem with a DOM document that I can't get rid of.
Actually this code already work for other HTML document but it doesn't for this last one here :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://r22.csmres.co.uk/_common/js/min/yui.js"></script>
<script type="text/javascript" src="http://r22.csmres.co.uk/_common/js/min/cp.js"></script>
<script type="text/javascript" src="http://r22.csmres.co.uk/_common/js/min/udm.js"></script>
<script type="text/javascript" src="http://r22.csmres.co.uk/_common/js/swfobject.js"></script>
<script type="text/javascript">
var Event = YAHOO.util.Event, Dom = YAHOO.util.Dom, $ = Dom.get;
Event.onDOMReady(function() {
csm_search.init('search-text', 'search-btn');
if (pagePeel != 'undefined') { sizedown987(); }
});
</script>
<!-- S:22 -->
<!-- G:16_08_54 -->
...
<title>Awesome Title</title>
</head>
...
</html>
And my Php code looks like this :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'NewsD');
$resultat = utf8_decode(curl_exec($ch));
curl_close($ch);
$Page = new DOMDocument();
@ $Page->loadHTML($resultat);
$title = $Page->getElementsByTagName('title')->item(0)->nodeValue;
I have used this code for several document (or webpage with the URL input variable) and this last one isn't working as my output $title is empty. And I can't understand why !
Thank you very much for your help !
Arthur
Upvotes: 0
Views: 760
Reputation: 11
I found the answer to my problem, actually a colleague of mine did !
The curlopt_returntransfer was returning a document deprived of all text. So he added this code to make sure that the function would return all of the text included in the page.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resultat = curl_exec($ch);
curl_close($ch);
Upvotes: 1