ric*_*ard 5 php replace special-characters
我很难尝试替换这个奇怪的右单引号字符.我正在使用这样的str_replace:
str_replace("’", '\u1234', $string);
看起来我无法弄清楚报价究竟是什么字符.即使我直接从PHPMyAdmin复制粘贴它仍然无法正常工作.我不得不以某种方式逃脱它吗?
角色: http ://www.lukomon.com/Afbeelding%204.png
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
编辑:它原来是一个微软左单引号,我可以用Phill Paffords评论中的这个函数替换.不确定我现在要标记哪个答案..
这也发生在我身上.几件事:
使用htmlentities
功能为您的文字
$my_text = htmlentities($string, ENT_QUOTES, 'UTF-8');
使用适当的文档类型,这对我有用.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
在您的页面中使用utf-8编码类型:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
这是您页面的最终原型:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// your code related to database
$my_text = htmlentities($string, ENT_QUOTES, 'UTF-8');
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
.
但是,如果要替换它,请尝试使用该mb_ereg_replace
功能.
例:
mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
$my_text = mb_ereg_replace("’","'", $string);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26344 次 |
最近记录: |