Three problems in Debugging a PHP program _php tips

Source: Internet
Author: User
Tags curl php script
the 1,filesize () function returns the wrong value.
When you download a page to local using curl, you need to read the contents of the downloaded temporary file tmpHtml.txt into a buffer. Because I use fread () to read, I need to pass in the size to read, so first use FileSize ('./tmphtml.txt ') to get the temporary file size. Strange is, get to the temporary file size is incorrect, the next breakpoint debugging, after FileSize () call, manual to find files on the hard disk, file size and filesize () results are different.
Searching for filesize on php.net, you can see in the function Description: note: The result of this function is cached. See Clearstatcache () for more details.
Then go to Clearstatcache () and find out why:
PHP caches the return information of these functions (which provide a function table for querying) to provide faster performance. In some cases, however, you may want to erase the cached information. For example, if you check the same file multiple times in a script, and the file is in danger of being deleted or modified during the execution of this script, you need to clear the file state cache. In this case, you can use the Clearstatcache () function to clear the file information cached by PHP.
2, in the UTF-8 coded PHP script, how to match Chinese when the GBK encoded Chinese Web page content does pattern match.
In yesterday's development, it was necessary to match the content containing the GBK encoded string ' Apple ', so write the following code:
Copy Code code as follows:

$pat = '/<\/a>/";
$pat = Iconv (' UTF-8 ', ' GB2312 ', $pat);
$ret = Preg_match_all ($pat, $contents, $matches);

But the dead and dead match is not, so try to first convert the content to UTF-8 encoding, as follows:
Copy Code code as follows:

$pat = '/<\/a>/";
$contenst = Iconv (' GB2312 ', ' UTF-8 ', $contents);
$ret = Preg_match_all ($pat, $contents, $matches);

So it can match up. But it doesn't make sense to suspect that there is a scam.
But the tragedy is, today again with the first method, and the match. It seems the problem is somewhere else.
Ah! The old man is a pig, problem 2 is caused by question 1! FileSize () Get the wrong, natural matching is not up! The second way to match is to solve the problem after 1 Ah!

3, the browser to review the elements of the quote picture download address, and curl get the download address is different.
possible...... The final answer is still: I am a pig.
Because the URI object is: attachment.php? Aid=mzk3mtb8ytg5ztyyntj8mtmynjcyndewmxw5nwyydc9aoue0a05evm9ydlersfbramzjnwjql1nhdwjlk3zrau9gtdzydnbudw%3d%3d &nothumb=yes
What is aid? It may be a session-related dongdong, change is also very normal. Then it's okay to grab something that looks like a static path.

The above three stories contain two tragedies, which is the low-level error that PHP beginners must 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.