Home >Backend Development >PHP Problem >What to do if php reads txt garbled characters
The solution to reading garbled txt in php: first download and install the Editplus software; then re-encode the txt text to be read; finally, use php to read a random line of the specified txt text.
Solution to the problem of garbled text content in PHP reading txt text
First of all, let’s talk about the encoding format of txt file ANSI, Unicode, UTF-8, Unicode Big Endian, generally the default is ANSI. Directly using PHP to read will definitely cause garbled code, because the web page encoding is generally UTF-8 or GB2312.
After reading many solutions from masters, I feel it is too complicated. In fact, if it is not commonly used, you only need to use Editplus software to re-encode the txt text you want to read.
php reads a random line of content from the specified txt text
<?php $arr=file('u.txt'); $n=rand(0,count($arr)); echo $arr[$n]; ?>
As shown:
For more related knowledge, please visit PHP Chinese website!
The above is the detailed content of What to do if php reads txt garbled characters. For more information, please follow other related articles on the PHP Chinese website!