简体   繁体   中英

How can I print special HTML characters correctly, using PHP?

I'm trying to print a string, like this:

Noticias de Fútbol.

But when I print this string, it displays like this:

Noticias de F tbol.

I tried htmlspecialchar() and many more, but my output remains the same.

$str = "Noticias de Fútbol";
$strfoot = html_entity_decode($str);

How can I resolve this?

您不需要使用html_entity_decode ,只需使用echo即可打印出$str ,但是您必须确保html在<head>包含以下代码行:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 

You are most likely outputting to a page that has the wrong charset specified. To confirm this open a JavaScript console and evaluate window.document.charSet and window.document.characterSet .

If that is the case you can use a meta tag to inform the browser of your intended charset:

<meta content="text/html; charset=utf-8">

I'm reading elsewhere the tag might be:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

You have use charset utf 8 and htmlentities function of php

Like

<meta http-equiv="content-type" content="text/html; charset=utf-8">

$test=htmlentities("Sisälämpötila");

echo $test;

Your php file is not utf-8 but the browser is reading it as utf-8 which is giving you that question mark character. Save your file as utf-8, most editors/ides have options to set the charset of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM