新学习static function为什么返回数据为空?
最近在学习static function,构建一个这样的代码。CURL获取网页源码,正则取出title等,为什么我的代码什么也没有返回?哪里的问题?能否详细解释一下?谢谢。
<br /> $url = 'www.php.net/archive/2012.php';<br /> if (!$url){<br /> exit;<br /> }<br /> echo TestClass::getTitle($url);<br /> class TestClass<br /> {<br /> static function getTitle($url)<br /> {<br /> $text = self::getHtml($url);<br /> preg_match("/(<h1.*>)(.*)(<\/h1>)/is",$text,$h1tags); <br /> $title = $h1tags[0];<br /> if (!$title) return false;<br /> return $title;<br /> }<br /> static function getHtml($url){<br /> $ch = curl_init();<br /> curl_setopt($ch, CURLOPT_URL, $url);<br /> $htmls = curl_exec($ch);<br /> curl_close($ch);<br /> if (!$htmls) return false;<br /> return $htmls;<br /> }<br /> }
$url = 'www.php.net/archive/2012.php';<br />$ch = curl_init();<br />curl_setopt($ch, CURLOPT_URL, $url);<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br />$htmls = curl_exec($ch);<br />curl_close($ch);<br />echo $htmls;