简体   繁体   中英

PHP Problems translating ASCII characters Function chr()

I have a problem translating characters with the ascii table. Example rare quotes like “ or ” 'or'

Part of the code

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

Someone can know what is due, it seems that you can not find the characters in the string

This might help you solve any issues:

<?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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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