Three problems encountered when debugging a PHP program _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Three problems encountered when debugging a PHP program. 1. the filesize () function returns an error value. When you use curlto download a page to a folder, you can read the contents of the downloaded tmphtml.txt file to a buffer zone. Because of my 1. the filesize () function returns an error value.
When you use curlto download a page to a folder, you can read the contents of the downloaded tmphtml.txt file to a buffer zone. Because I use fread () for reading and need to input the size of the file to be read, I first use filesize ('./tmpHtml.txt') to obtain the temporary file size. The strange thing is that the size of the temporary file obtained is incorrect. for breakpoint debugging, after filesize () is called, manually search for the file, the file size and filesize () on the hard disk () different results are obtained.
Search for filesize on php.net. you can see the following statement in the function description: Note: the result of this function will be cached. See clearstatcache () for more details.
Check clearstatcache () again and find the reason:
PHP will cache the returned information of these functions (providing function tables for query) to provide faster performance. However, in some cases, you may want to clear the cached information. For example, if you check the same file multiple times in a script and the file may be deleted or modified during script execution, you need to clear the file status cache. In this case, you can use the clearstatcache () function to clear the file information cached by PHP.
2, in the UTF-8 encoding PHP script, the GBK encoding of Chinese Web content pattern matching, how to match Chinese.
In yesterday's development, you need to match the content containing the GBK encoding string 'apple', so write the following code:

The code is as follows:


$ Pat = '/<\/a> /';
$ Pat = iconv ('utf-8', 'gb2312', $ pat );
$ Ret = preg_match_all ($ pat, $ contents, $ matches );


But the life and death match, so try to convert the content into UTF-8 encoding, as follows:

The code is as follows:


$ Pat = '/<\/a> /';
$ Contenst = iconv ('gb2312', 'utf-8', $ contents );
$ Ret = preg_match_all ($ pat, $ contents, $ matches );


So we can match it. But I cannot figure it out. I suspect there is fraud.
However, the tragedy is that today the first method is used and matched again. It seems that the problem is somewhere else.
Ah! Old man is a pig, problem 2 is caused by problem 1! Filesize () is incorrect. it cannot be matched! The second method is matched after problem 1 is solved!

3. Why is the quotation image obtained by the review element in the browser different from that obtained by curl.
Maybe ...... The final answer is: I am a pig.
Because the URI object is: attachment. php? Aid = assist % 3D % 3D & nothumb = yes
What is aid? It may be something related to the session. it is normal to change it. After that, it would be okay to catch something that looks like a static path.

The above three stories contain two tragedies, which are the basic mistakes that PHP beginners must make.

The http://www.bkjia.com/PHPjc/324920.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324920.htmlTechArticle1,filesize () function returns an error value. When you use curlto download a page to a folder, you can read the contents of the downloaded tmphtml.txt file to a buffer zone. Because I make...

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.