Home  >  Article  >  php教程  >  有趣的聊天网站

有趣的聊天网站

WBOY
WBOYOriginal
2016-06-06 19:37:491537browse

借助图灵机器人提供的免费智能聊天接口来实现的一个网页版聊天,感兴趣的朋友可以体验下,http://talkingrobot.sinaapp.com/liangzai.php 无 $apiKey = "自己的apiKey"; $apiURL = "http://www.tuling123.com/openapi/api?key=KEYinfo=INFO"; // 设置报文头,

借助图灵机器人提供的免费智能聊天接口来实现的一个网页版聊天,感兴趣的朋友可以体验下,http://talkingrobot.sinaapp.com/liangzai.php 
$apiKey = "自己的apiKey"; 
 $apiURL = "http://www.tuling123.com/openapi/api?key=KEY&info=INFO"; 


// 设置报文头, 构建请求报文 
header("Content-type: text/html; charset=utf-8"); 
 $reqInfo = "讲个笑话"; 
 $url = str_replace("INFO", $reqInfo, str_replace("KEY", $apiKey, $apiURL)); 



/** 方法一、用file_get_contents 以get方式获取内容 */ 
      $res =file_get_contents($url); 
      echo $res; 



/** 方法二、使用curl库,需要查看php.ini是否已经打开了curl扩展 */ 
     $ch = curl_init(); 
     $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
     $file_contents = curl_exec($ch); 
     curl_close($ch); 
     echo $file_contents; 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn