HAhahaha Maybe there are no errors...? I remembered that IE has a console which shows errors, so I opened the whole thing in IE (latest) and the only error it showed was concerning my doctype. It told me to change this:
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"
In to this:
"<!DOCTYPE html>"
After doing this I had no errors..but it still doesn't work..no alerts what so ever.
yes, but for some reason you are getting the data OK, but "headlines" is an empty array for the metadata, so there is nothing to alert... it seems like the php is not pulling in the metadata. It could be an x-path thing, but I don't know much about that. You can do this easily enough with the yahoo yql...
yes, but for some reason you are getting the data OK, but "headlines" is an empty array for the metadata, so there is nothing to alert... it seems like the php is not pulling in the metadata. It could be an x-path thing, but I don't know much about that. You can do this easily enough with the yahoo yql...
Yes I know, that's how I was doing it before. But the thing with yql is that you have to wait for it to respond. Sometimes it respond to slow, especially in the evening and in the weekend, and I also experienced times where the yql did not respond at all. Therefore I can not rely on yql. Furthermore I'm planning to do more with the data involving others 'calls' to other api's. Yql is one to many. Thanks for trying anyway
<?php
header("content-type: text/html; charset=utf-8");
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache, must-revalidate");
header("pragma: no-cache");
$chnMta='';
if(isset($_GET['ste'])){ echo $_GET['ste'].'<br>';
$html = file_get_contents($_GET['ste']);
// echo $html;
// We capture only the meta tags
if (preg_match_all("@<(meta[^>]+/?)>@",$html,$m,PREG_PATTERN_ORDER)){
foreach($m[1] as $k=>$v) $chnMta.='<'.$v.'><br>';}
}
echo $chnMta;
?>
I do not use jQuery, but prefer something like this :
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div id="rsp"></div>
<script type="text/javascript">
(function(){
var xmlObj=false;
var xmlFct=[function(){return new XMLHttpRequest()}
,function(){return new ActiveXObject("Msxml2.XMLHTTP")}
,function(){return new ActiveXObject("Msxml3.XMLHTTP")}
,function (){return new ActiveXObject("Microsoft.XMLHTTP")}];
for (var i=0;i<xmlFct.length;i++) {try{xmlObj = xmlFct[i]();}catch(e){continue;}break;}
return sndRqt=function(url,cllbck,pstDta){
var req=xmlObj;
if (!req) return;
var mth=(pstDta)? "POST":"GET";
req.open(mth,url,true);
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
if (pstDta) req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.onreadystatechange=function(){
if (req.readyState!=4) return;
if (req.status!=200 && req.status!=304) return;
cllbck(req);}
if (req.readyState==4) return;
req.send(pstDta);
};
}());
var url='http://www.bbc.co.uk/news';
sndRqt('prxy.php?ste='+encodeURIComponent(url),function(r){
document.getElementById('rsp').innerHTML=r.responseText});
</script>
</body>
</html>
It would be possible to capture only the description, contents, keywords... with other regular expressions on the $v values...
Last edited by 007Julien; 12-28-2012 at 08:23 PM.
Reason: complements, errors
@007Julien Thank you very much, your code is working 100% To bad it's not Jquery, I don't know PHP. But then again its a very small code, I don't expect trouble in the future regarding my ignorance with PHP.
Bookmarks