There is a text file with the contents. I'm cutting it down

$rf=fopen('1.txt','w+'); ftruncate($rf,100) 

Why now when opening a file instead of letters I have such black squares and when opening a file, the message "open binary file?" Return Values ​​- Returns TRUE.

  echo ftruncate ( $rf, 2000 );//1 
  • one
    wasn’t it an Unicode text hour? - VladD
  • Something tells me that you are right. Probably the text file was not created in the same encoding. The file had only letters and line breaks. - koza4ok

1 answer 1

If the text was in Unicode format, then cutting it in a "random" place, you spoiled it. The fact is that Unicode characters have a length in bytes greater than 1 (in some cases it is always 2, in some a variable number), and a BOM is possible at the beginning of the file (as far as I know, it usually has a length of 3 - odd). Therefore, it is likely that your cut came in the middle of the symbol. Faced with this, the editor will not perceive the file as Unicode, but will try to interpret it as text.

A simple solution is this: open the file as a text file, read the first x characters, and write it down, saving the format to another file. Should work.

  • thank you very much. - koza4ok
  • @ koza4ok: please! - VladD