Chinese garbled characters are mostly caused by encoding. We only need to adjust the output encoding to solve the problem of Chinese garbled characters. Let’s look at the solution to the Chinese garbled characters of simplexml_load_file.
In PHP5.0, simplexml_load_file() is a good function for reading and processing XML files, but garbled characters will appear when reading and processing Chinese. After research, it was found that if it is Chinese content, it must go through iconv Encoding conversion, otherwise it will be displayed as garbled characters.
The code is as follows
|
Copy code
|
||||||||
$xml=simple_load_file('xml file'); foreach($xml->soft as $temp){ echo $temp->mem; //This is the software description.
English is correct and Chinese is garbled. I guess this is an encoding problem. Later I found related articles online, such as the core sentence1. If the encoding of xml does not match the file type, an error will be reported immediately
|
3. No matter what the file content is, after processing, it will be UTF8.
The code is as follows |