【问题标题】: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
有人可以知道是什么原因,似乎找不到字符串中的字符
【问题讨论】:
标签:
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;
?>