每日60秒读懂世界-文字版
之前是有些同学问我有没有每日60S的文字版,一直没啥时间,闲余之际,给有需要的同学弄了下。
就是抓的知乎的一个博主--每日60秒读懂世界
接口是:https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items
请求一次会给出10条数据,下标为0的是最新的那条,所以我们每次都去获取下标为0的那条就行
演示地址:https://api.03c3.cn/zb/text.php
<?php
/*
* @Descripttion:
* @version:
* @Author: lengxiaoyu
* @Date: 2022-05-25 18:07:26
* @LastEditTime: 2022-06-21 17:47:59
*/
header("Content-Type: text/html;charset=utf-8");
header("Content-Type: text/json; charset=$charset");
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Methods:GET');
header('Access-Control-Allow-Headers:x-requested-with, content-type');
require('phpQuery/phpQuery.php');
$a = file_get_contents("https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items");
$data = json_decode(Unicode($a))->{"data"};
$html = $data[0]->{"url"};
phpQuery::newDocumentFile($html);
$p = pq('p')->text();
echo ($p);
// 编码转换
function Unicode($str)
{
return preg_replace_callback(
"#\\\u([0-9a-f]{4})#i",
function ($r) {
return iconv('UCS-2BE', 'UTF-8', pack('H4', $r[1]));
},
$str
);
}
之所以有个unicode的编码转换函数,是因为我尝试了其他好几种方法似乎都不行,所以才去复制了一个函数来用