When PHP handles HTML, string truncation

Source: Internet
Author: User
Tags truncated
Stream=fopen ("xxx.html"); var str = "; while (!feof (stream) {      size+=1024;     Str.=fread (stream,size);} ....


STR can only get 1024 bytes, the back is more than truncated, but Fread did read, is not used. = Is there a problem, or is there a special character in the HTML that causes truncation?
Thank you, great God.


Reply to discussion (solution)

$stream =fopen ("Test.txt", "A +"), $str = "; $size =1024;while (!feof ($stream)) {$str. =fread ($stream, $size);} Fclose ($stream); Echo $str;

$stream =fopen ("Test.txt", "A +"), $str = "; $size =1024;while (!feof ($stream)) {$str. =fread ($stream, $size);} Fclose ($stream); Echo $str;


I read the HTML, with the read mode should be OK, some pages can be crawled, some page crawl is truncated, doubt an HTML tag problem? Thank you

As far as the code above is concerned, you can't run it, maybe you wrote it wrong.
As for some special character of the HTML you said, it should not exist.
And you just read an HTML, the data is not big, it is recommended to use file_get_contents (), better performance than fread

You're not the PHP code.

As far as the code above is concerned, you can't run it, maybe you wrote it wrong.
As for some special character of the HTML you said, it should not exist.
And you just read an HTML, the data is not big, it is recommended to use file_get_contents (), better performance than fread


Well, I wrote, probably meaning, just started to change the cms,php entry level.
You write very right, but I do encounter problems, debugging, every time while inside the fread can read the data, but, added to the string str inside, the length of STR changed, but the content of each increase, is debugging the problem, debugging can only show the variable part? I changed the xdebug display maximum length, no effect, I use the vs.php debugging, how to show all. How can you see how much str has been saved, see the length of its increase, not seen the content changes

You use

$stream =fopen ("test.html", "R"); $str = "; $size =1024;while (!feof ($stream)) {$tmp =fread ($stream, $size); file_put_ Contents (' D:/log.log ', $tmp. Php_eol,file_append); $str. = $tmp; $tmp = ";} Fclose ($stream); Echo $str;

Run the program, and then open Log.log view, each row is the data read by each while loop

What code are you? C?

You use

$stream =fopen ("test.html", "R"); $str = "; $size =1024;while (!feof ($stream)) {$tmp =fread ($stream, $size); file_put_ Contents (' D:/log.log ', $tmp. Php_eol,file_append); $str. = $tmp; $tmp = ";} Fclose ($stream); Echo $str;

Run the program, and then open Log.log view, each row is the data read by each while loop


Okay, I'll try, good man.
  • 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.