Skip to content

Instantly share code, notes, and snippets.

@robertbrook
Created March 11, 2011 16:22
Show Gist options
  • Save robertbrook/866115 to your computer and use it in GitHub Desktop.
Save robertbrook/866115 to your computer and use it in GitHub Desktop.
<!--
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ index.php?$1 [L]
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?$1 [L]
-->
<?php
$queryUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20url%20from%20search.web%20where%20query%3D%22inurl%3A" . urlencode($_SERVER['QUERY_STRING']) . "%22%20and%20sites%20%3D%20%22bbc.co.uk%22%20limit%201&format=json";
$session = curl_init($queryUrl);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($session);
curl_close($session);
$yqlObject = json_decode($json);
header('Location: ' . $yqlObject->{'query'}->{'results'}->{'result'}->{'url'});
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>PHP and YQL Demo</title>
</head>
<body style="font-family: Arial,Helvetica,sans-serif;">
<div style="padding: 5px">
<?php
print $yqlObject->{'query'}->{'results'}->{'result'}->{'url'};
// print $queryUrl;
?>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment