Skip to content

Instantly share code, notes, and snippets.

@smzk
Created March 7, 2014 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smzk/9409389 to your computer and use it in GitHub Desktop.
Save smzk/9409389 to your computer and use it in GitHub Desktop.
<?php
$of = isset($_GET['of']) ? $_GET['of'] : 0;
if($of == 0){
$of= 0;
}
$html = file_get_contents('http://b.hatena.ne.jp/entrylist?of=' . $of);
$html = str_replace("\n", '', $html);
preg_match_all('/(?<=\<div class="entry-contents"\>)(.*?)(?=\<\/div\>)/', $html, $matches);
$result = array();
foreach($matches[1] as $match){//var_dump($match);
preg_match_all('/(?<=a href=")(.*?)(?=")(?:.*?)(?<=title=")(.*?)(?=")/', $match, $aMatch);
$result[] = array(
'url' => $aMatch[1][0],
'title' => $aMatch[2][0],
);
}
header("Access-Control-Allow-Origin: *");
echo json_encode($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment