简体   繁体   English

如何使用php将此(')字符转换为html实体?

[英]How can I convert this (′) character to html entities using php?

I want to make this character (′) html entity for storing in my database using php. 我想使用php将这个字符(')html实体存储在数据库中。 I am using MySQL databse. 我正在使用MySQL数据库。 I use: 我用:

$string = "HTML5′s placeholder Attribute";
$newStr = htmlspecialchars($string, ENT_QUOTES);
echo $newStr;

the above code prints the following 上面的代码打印以下内容

HTML5â?²s placeholder Attribute 

How can I make this (′) character an HTML entity? 如何使这个(')字符成为HTML实体?

You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. 您需要在此处使用htmlentities() ,因为特定的引号thingy通常不需要转义。 And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes: 并且您还需要指定字符集,否则您将获得与Latin-1等效的转义符:

echo htmlentities("′", ENT_QUOTES, "UTF-8");

Should either get you ′ 应该可以让您′ or ′ ′ as result. 结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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