Home  >  Article  >  Backend Development  >  What should I do if the question mark in php is garbled?

What should I do if the question mark in php is garbled?

coldplay.xixi
coldplay.xixiOriginal
2020-07-23 14:38:412650browse

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.

What should I do if the question mark in php is garbled?

Solution to php question mark garbled code:

The original code is:

<?php echo substr($res[&#39;art_title&#39;],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[&#39;art_title&#39;],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[&#39;art_title&#39;],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!

Statement:
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