说明:在微信发送消息的时候出现的问题 => 字数超出限制,导致服务器报错。
解决:加一个判断语句。。。
具体了解:/question/1732766623684784587.html
<?php// 计算字符串长度,以utf-8编码的标准计算(微信是以utf-8为单位的吧)function utf8_strlen($string) {// 将字符串分解为单元preg_match_all("/./us", $string, $match);// 返回单元个数return count($match[0]);}// 下面是对历史上的今天文件的处理源码,没什么用,并将返回的语句字数上做出相应的处理。if (isset($_GET["m"]) && isset($_GET["d"])) {$m=$_GET["m"];$d=$_GET["d"];$filepath= $m."/".$d.".txt";$f = file_get_contents($filepath);// print_r (json_decode($f));$list = json_decode($f);$str="";for ($i=0;$i<count($list);$i++) {if (isset($list[$i]->title)) {$title=$list[$i]->title;} else {$title="";}$son=$list[$i]->solaryear . "-" . $m . "-" . $d . ": <a href='" . $list[$i]->url . "'>" . $title . "</a>\n";if (utf8_strlen($str.$son)>=1000) {//为了保险,设置小一点了,😫$str .= "......\n";break;}$str .= $son; }echo $str;} else {}
最简单的方法:
$res = mb_substr($result, 0, 2048, 'UTF-8')