?php
include_once('simple_html_dom.php');
$string="SAN DIEGO — Karl Deisseroth is having a very early breakfast before the day gets going at the annual meeting of the Society for Neuroscience. Thirty thousand people who study the brain are here at the Convention Center, a small city’s worth of badge-wearing, networking, lecture-attending scientists.
For Dr. Deisseroth, though, this crowd is a bit like the gang at Cheers — everybody knows his name. He is a Stanford psychiatrist and a neuroscientist, and one of the people most responsible for the development of optogenetics, a technique that allows researchers to turn brain cells on and off with a combination of genetic manipulation and pulses of light.
He is also one of the developers of a new way to turn brains transparent, though he was away when some new twists on the technique were presented by his lab a day or two earlier.";
$string=explode(".",$string);
$check_uniqueness=array();
foreach($string as $val) {
if(strlen($val)>100) {
$check_uniqueness[]=substr($val,0,100);
}
}
$result_array=array();
foreach($check_uniqueness as $val) {
$time=slice_text($val);
if(!empty($time)) {
$result_array = array_merge ($time, $result_array);
}
}
shuffle($result_array);
$result_array = array_slice($result_array, 0,5);
foreach($result_array as $val) {
$find_url=get_page_curl($val,"google");
$html = str_get_html($find_url);
foreach ($html->find(".onebox_result") as $node){
$node->outertext = '';
}
foreach($html->find('div') as $element) {
$str=strip_tags($element->innertext);
$str=str_replace(" ","",$str);
$element->innertext=$str;
}
$val_seach=str_replace(" ","",$val);
if(preg_match("/$val_seach/is",$html)) {
echo $val."\n";
}
}
function slice_text($text) {
$text=str_split($text,1);
$find_array;
$lit="";
foreach($text as $val) {
if(preg_match("/[A-Za-z0-9]| |\.|,/is",$val)) {
$lit.=$val;
} else {
$find_array[]=$lit;
$lit="";
}
}
$find_array[]=$lit;
foreach($find_array as $k=>$v) {
if(strlen($v)<40) {
unset($find_array[$k]);
}
}
return $find_array;
}
function get_page_curl($text_search,$resource) {
switch($resource) {
case "google" :
$url="http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q=";
break;
case "yandex" :
$url="http://yandex.ru/yandsearch?&text=";
break;
}
$useragent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.14912/870; U; id) Presto/2.4.15";
$ch = curl_init ("");
$text_search=urlencode($text_search);
curl_setopt ($ch, CURLOPT_URL, $url.$text_search);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec ($ch);
curl_close($ch);
return $output;
}
?>