1

我正在尝试将 UTF 中欧元的多字节字符(在我的 html 中显示为 â¬)preg_replace 为“$”,将 * 替换为“@”

$orig = "2 **** reviews  ⬠19,99 price";
$orig = mb_ereg_replace(mb_convert_encoding('€', 'UTF-8', 'HTML-ENTITIES'), "$", $orig);
$orig = preg_replace("/[\$\;\?\!\{\}\(\)\[\]\/\*\>\<]/", "@", $orig);
$a = htmlentities($orig);
$b = html_entity_decode($a);

“*”被替换,但“⬔没有被替换......

也尝试将其替换为

$orig = preg_replace("/[\xe2\x82\xac]/", "$", $orig);

也不转换....

另一个不起作用的计划:

$orig= mb_ereg_replace(mb_convert_encoding('&#x20ac;', 'UTF-8', 'HTML-ENTITIES'), "$", $orig);

Brrr 有人知道如何摆脱这个 utf8 欧元字符:

echo html_entity_decode('&euro;');

(使我抓狂)

4

3 回答 3

4

这可能是由两个原因造成的:

  1. 实际的源文本是 UTF8 编码的,但您的 PHP 代码不是。您可以通过使用这一行来解决这个问题并保存您的文件 UTF8 编码(尝试使用记事本++)。

    str_replace('€', '$', $source);

  2. 源文本已损坏:多字节字符被转换为 latin1(错误的数据库字符集?)。您可以尝试将它们转换回 latin1:

    str_replace('€', '$', utf8_decode($source))

于 2012-06-21T19:14:49.443 回答
0

在此处粘贴我的评论作为答案,以便您标记它!

不会

str_replace(html_entity_decode('&euro;'), '$', $source)

工作?

于 2012-06-21T18:23:44.587 回答
0
于 2012-10-20T16:32:36.630 回答