新学习static function为什么返回数据为空?

mumubangditu mumubangditu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在学习static function,构建一个这样的代码。CURL获取网页源码,正则取出title等,为什么我的代码什么也没有返回?哪里的问题?能否详细解释一下?谢谢。


$url = 'www.php.net/archive/2012.php';
if (!$url){
exit;
}
echo TestClass::getTitle($url);
class TestClass
{
static function getTitle($url)
{
$text = self::getHtml($url);
preg_match("/(<h1.*>)(.*)(<\/h1>)/is",$text,$h1tags);
$title = $h1tags[0];
if (!$title) return false;
return $title;
}
static function getHtml($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$htmls = curl_exec($ch);
curl_close($ch);
if (!$htmls) return false;
return $htmls;
}
}
...全文
评论 8
收藏 已收藏
分享
返回顶部
mumubangditu
基础编程 21,889 成员 140,329 内容