New Learning static function why return data is empty

Source: Internet
Author: User
New Learning static function Why is the returned data empty?
Recently in learning the static function, build a code like this. Curl Gets the Web page source code, take out the title and so on, why does my code return nothing? Where's the problem? Can you explain it in detail? Thank you.


$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>)/is", $text, $h 1tags);
$title = $h 1tags[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;
}
}

------Optimal Solution--------------------
That's your regular string of mistakes.
/( ) (. *) (<\/h1>)/is
------Other Solutions--------------------
Initializes a new object, instantiates
------Other Solutions--------------------
This post was last edited by xuzuning on 2012-11-10 15:32:54 your code is not able to display the entire page?

Of course, to make your code run as you expect, you also need to
curl_setopt ($ch, Curlopt_returntransfer, true);
In $htmls = Curl_exec ($ch); Before


------Other Solutions--------------------
Citation:
This post was last edited by xuzuning on 2012-11-10 15:32:54
Isn't it possible to run your code to show the entire page?

Of course, to make your code run as you expect, you also need to
curl_setopt ($ch, Curlopt_returntransfer, true);
In $htmls = Curl_exec ($ch); Before


Set, or output blank, nothing, my php Version 5.3.8.
I want to go back to the regular out

the text part.
------Other Solution--------------------

reference:
First new object, real To instantiate a


How about a new method? No.
------Other Solutions--------------------
So you're probably not loading curl extensions?
------Other Solutions--------------------
reference:
that you might not be loading Curl extension? The

Simple Curl code can return the contents of the www.php.net. But build a static function, but nothing.
 $url = ' www.php.net/archive/2012.php '; 
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, true);
$htmls = curl_exec ($ch);
Curl_close ($ch);
Echo $htmls;


------Other Solutions--------------------
reference:
That's your regular rule. The string is incorrectly
/( ) (. *) (<\/h1>)/is

Does it make sense to remove the IS?
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.