JSON

微信开发小功能(2)

字号+ 作者:H5之家 来源:H5之家 2017-03-21 17:07 我要评论( )

?php$msg=$this-message['content'];//文本消息内容$id=$this-message['from'];//用户ID$msgid=$this-message['msgid'];//消息ID$time=$this-message['time'];//消息发送时间$str=file_get_contents('http://domain


<?php $msg = $this->message['content']; // 文本消息内容 $id = $this->message['from']; // 用户ID $msgid = $this->message['msgid']; // 消息ID $time = $this->message['time']; // 消息发送时间 $str=file_get_contents('http://domain.com/news.php'); $info=json_decode(trim($str,chr(239).chr(187).chr(191)),true); //print_r($info); $news=$info['news1']; //print_r($news); $result=''; for($i=0;$i<count($news);$i++){ $result.='<a href="'.$news[$i]['src'].'">'.$news[$i]['title'].'</a>'."\n\n"; } $result=rtrim($result); return $this->respText($result);

处理部分:

<?php header("Content-type:text/html;charset=utf-8"); require 'QueryList/QueryList.class.php'; $url = "http://www.hkxy.edu.cn/"; $reg = array(     "title" => array("td>a","text"),     "src" => array("td>a","href"), ); //$rang = "[id^=post-]"; $hj = QueryList::Query($url,$reg); //$hj = QueryList::Query($url,$reg,$rang); for($i=0;$i<count($hj->jsonArr);$i++){ //$hj->jsonArr[$i]['title']=html_entity_decode(($hj->jsonArr[$i]['title']),ENT_NOQUOTES,'utf-8'); $hj->jsonArr[$i]['title']=str_replace('&#160;','',$hj->jsonArr[$i]['title']); $hj->jsonArr[$i]['title']=iconv('gbk', 'utf-8', $hj->jsonArr[$i]['title']); $hj->jsonArr[$i]['src']='http://www.hkxy.edu.cn'.$hj->jsonArr[$i]['src']; } //print_r($hj->jsonArr); for($i=0;$i<5;$i++){ $arr['news1'][$i]=$hj->jsonArr[$i]; $arr['news2'][$i]=$hj->jsonArr[$i+17]; $arr['news3'][$i]=$hj->jsonArr[$i+25]; } //print_r($arr); $str=json_encode($arr); function arrayRecursive(&$array, $function, $apply_to_keys_also = false) {     static $recursive_counter = 0;     if (++$recursive_counter >1000 ) {         die('possible deep recursion attack');     }     foreach ($array as $key => $value) {         if (is_array($value)) {             arrayRecursive($array[$key], $function, $apply_to_keys_also);         } else {             $array[$key] = $function($value);         }         if ($apply_to_keys_also && is_string($key)) {             $new_key = $function($key);             if ($new_key != $key) {                 $array[$new_key] = $array[$key];                 unset($array[$key]);             }         }     }     $recursive_counter--; } /**************************************************************  *  *  将数组转换为JSON字符串(兼容中文)  * @param  array $array 要转换的数组  * @return string      转换得到的json字符串  * @access public  *  *************************************************************/ function JSON($array) {     arrayRecursive($array, 'urlencode', true);     $json = json_encode($array);     return urldecode($json); } echo JSON($arr); //echo $hj->getJSON();

爱编程-编程爱好者经验分享平台

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评
t