[PHP] 纯文本查看 复制代码 <?php
error_reporting(0);
header('Content-Type:application/json;Charset=UTF-8');//html文件类型,UTF-8类型
$str = http_get('https://github.com/djun/wechatbot/blob/main/README.md');
$strr = getSubstr($str,'<code>','</code>');
echo $strr;
//取文本中间
function getSubstr($str, $leftStr, $rightStr)
{
$left = strpos($str, $leftStr);
//echo '左边:'.$left;
$right = strpos($str, $rightStr,$left);
//echo '<br>右边:'.$right;
if($left < 0 or $right < $left) return '';
return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
}
//取文本中间
//取网页源码
function http_get($url)
{
$Header=array( "User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
$con=curl_init((string)$url);
curl_setopt($con,CURLOPT_HEADER,False);
curl_setopt($con,CURLOPT_SSL_VERIFYPEER,False);
curl_setopt($con,CURLOPT_RETURNTRANSFER,true);
curl_setopt($con,CURLOPT_HTTPHEADER,$Header);
curl_setopt($con,CURLOPT_TIMEOUT,5000);
$result = curl_exec($con);
return $result;
}
?>
这样? |