Skip to content

Instantly share code, notes, and snippets.

@jamalsa
Created November 3, 2010 02:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamalsa/660704 to your computer and use it in GitHub Desktop.
Save jamalsa/660704 to your computer and use it in GitHub Desktop.
Use YQL to get title and description from website
<?php
// Set root url, which point to yahoo api
$root = 'http://query.yahooapis.com/v1/public/yql?format=json&diagnostics=true&callback=cbfunc';
// Get title from google
$titleUrl = $root . '&q=' . urlencode("select content from html where url = 'http://google.com' and xpath = '//title'");
// Get description from google
$descUrl = $root . '&q=' . urlencode("select content from html where url='http://google.com' and xpath = '//meta' and name='description'");
// Process it
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $titleUrl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
$title = curl_exec($c);
curl_setopt($c, CURLOPT_URL, $descUrl);
$description = curl_exec($c);
curl_close($c);
var_dump($title);
var_dump($description);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment