Copy Code code as follows:
<?php
function Simsimi ($keyword) {
$keyword = UrlEncode (UrlEncode ($keyword));
-----------Get cookies----------//
$url = "http://www.simsimi.com/";
$ch = Curl_init ($url);
curl_setopt ($ch, curlopt_header,1);
curl_setopt ($ch, curlopt_returntransfer,1);
$content = curl_exec ($ch);
List ($header, $body) = Explode ("\r\n\r\n", $content);
Preg_match ("/set\-cookie: ([^\r\n]*);/iu", $header, $matches);
$cookie = $matches [1];
Curl_close ($ch);
-----------Crawl reply----------//
$url = "http://www.simsimi.com/func/req?lc=ch&msg= $keyword &ft=0.0";
$ch = Curl_init ($url);
curl_setopt ($ch, Curlopt_referer, "http://www.simsimi.com/talk.htm?lc=ch");
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, Curlopt_cookie, $cookie);
$content = Json_decode (Curl_exec ($ch), 1);
Curl_close ($ch);
if ($content [' result ']== ' 100 ') {
$content [' response '];
return $content [' response '];
} else {
Return ' I will not answer the question ... ';
}
}
?>