Home > Backend Development > PHP Problem > What to do if php reads txt garbled characters

What to do if php reads txt garbled characters

藏色散人
Release: 2023-03-02 09:30:01
Original
3156 people have browsed it

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.

What to do if php reads txt garbled characters

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(&#39;u.txt&#39;);
    $n=rand(0,count($arr));
    echo $arr[$n];
?>
Copy after login

As shown:

What to do if php reads txt garbled characters

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template