Home > Article > Backend Development > What should I do if the question mark in php is garbled?
Solution to the garbled question mark in php: First use [mb_substr()], the code is [409b70f5a67511669e636bb4760ee0dc ]; Then use the last parameter of [mb_substr()] to add encoding.
Solution to php question mark garbled code:
The original code is:
<?php echo substr($res['art_title'],0,20);?>
I learned that substr()
would cause garbled characters when intercepting Chinese characters, so I changed it to mb_substr()
<?php echo mb_substr($res['art_title'],0,20);?>
. The local test was normal for a while, and then I changed the server and went online. After that, garbled characters appeared again
The query said it was because the encoding of the web page file and the database were different
I clearly remember that I set utf8 for both the database and the page file,
But I also found a solution, mb_substr()
Just add the encoding to the last parameter
<?php echo mb_substr($res['art_title'],0,20,"utf-8");?>
Related learning recommendations:PHP programming from entry to proficiency
The above is the detailed content of What should I do if the question mark in php is garbled?. For more information, please follow other related articles on the PHP Chinese website!