$ Out = "" and then $ out. = What is the difference with direct $ out =? the above example is provided.

Source: Internet
Author: User
Tags socket error
$ Out & quot; and then $ out. what is the difference between it and $ out? the following example shows PHPcode $ fp @ fsockopen ($ whoisserver, $ port, $ errno, $ errstr, $ timeout) ordie (& quot; socketError & quot ;. $ errno. & quot; $ out = "" and then $ out. = What is the difference from direct $ out =? The following is an example.
PHP code
  $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);    fputs($fp, $domain . "\r\n");    $out = "";    while (!feof($fp)){$out .= fgets($fp);}    fclose($fp);

Ask here
PHP code
  $out = "";    while (!feof($fp)){$out .= fgets($fp);}

Yu and
PHP code
      while (!feof($fp)){$out= fgets($fp);}


What is the difference?

------ Solution --------------------
The initialization operation. if the $ out type is not initialized, it is null. it is different from the string type you want. you can check it with var_dump.

If $ out is used for condition determination, unexpected results may be obtained without initialization.
------ Solution --------------------
$ Out = "";
While (! Feof ($ fp) {$ out. = fgets ($ fp );}
All content in the $ fp file can be obtained.

$ Out = "";
While (! Feof ($ fp) {$ out = fgets ($ fp );}
The last line of the $ fp file is obtained.

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.