Convert all HTML special chars to UTF-8 in PHP?

2019-06-25 04:42发布

问题:

Can somebody help me? How can i convert all HTML special chars to UTF-8 Example:

Hello Word! P&H

convert to:

Hello Word! P&H

回答1:

Use html_entity_decode() and explicitly specify the charset:

$string = html_entity_decode($string, ENT_QUOTES, "utf-8");

for future reference: PHP string functions