首页 > 代码库 > 获取笑话集网站笑话数据的后台代码
获取笑话集网站笑话数据的后台代码
最近做了一个app用于获取笑话集网站的数据,为了方便开发。我先用PHP对数据进行了预处理
代码如下
<?phpinclude_once("writeLog.php");class Joke{ var $jokeText = ""; var $urlNext = ""; var $urlPrv = ""; var $urlBase = "http://wap.jokeji.cn/"; function __construct() { } function getContent($url){ MyLog("url.log",$url); $html = file_get_contents(iconv("gb2312","UTF-8",$url)); $begin = stripos($html,"<div class=\"joketxt\">") + 23; $end = stripos($html,"<script",$begin); $r = substr($html, $begin, $end - $begin); $r = str_ireplace("<p>","",$r); $r = str_ireplace("</p>","",$r); $r = str_ireplace("<br>","\r\n",$r); $this->jokeText = $r; $begin = stripos($html,"上一篇:<a"); if ($begin != false) { $begin += 27; $end = stripos($html,"\"",$begin); $this->urlNext = substr($html, $begin, $end - $begin); } $begin = stripos($html,"下一篇:<a"); if ($begin != false) { $begin = $begin + 27; $end = stripos($html,"\"",$begin); $this->urlPrv = substr($html, $begin, $end - $begin); } } function getFirstLink() { $html = file_get_contents($this->urlBase); $begin = stripos($html,"<div class=\"list\">") + 42; $end = stripos($html,"\"",$begin); $r = substr($html, $begin, $end - $begin); return $r; } function getJoke($u){ if ($u == "") { $url = $this->urlBase.$this->getFirstLink(); } else { $url = $this->urlBase.urlencode($u); } $this->getContent($url); $joke = array(); $joke["content"] = $this->jokeText; $joke["next"] = $this->urlNext; $joke["previous"] = $this->urlPrv; return $joke; } }
获取笑话集网站笑话数据的后台代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。