【问题标题】:PHP Problems translating ASCII characters Function chr()PHP 转换 ASCII 字符的问题 Function chr()
【发布时间】:2023-03-08 13:25:01
【问题描述】:

我在用 ascii 表翻译字符时遇到问题。 示例罕见的引号,如“或”'或'

部分代码

$txt = str_replace(chr(147), '"', $txt );    // left double quote

有人可以知道是什么原因,似乎找不到字符串中的字符

【问题讨论】:

  • 147 不是双引号。
  • 在这里查看扩展的 ASCII 码:asciitable.com

标签: php string char ascii str-replace


【解决方案1】:

这可能会帮助您解决任何问题:

<?php
/* to avoid diamond shaped / garbled character output in browser
make the browser uses the correct encoding. Use a header.
*/
header("Content-Type: text/html; charset=ISO-8859-1");
$chr = chr(147);
echo 'replacing ' . $chr . ' in target string.' . '<br />';
$txt = 'sometext' . $chr . 'andthensomemore' . $chr . 'andterminate';
echo 'BEFORE : ' . $txt . '<br />';
$txt = str_replace($chr, '"', $txt );
echo 'AFTER : ' . $txt;
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多