开发者

PHP character change

My PHP application changes 开发者_Go百科my apostrophe character to â��

What is my crime?


Click the Microsoft Office Button , and then click Word Options.

Click Proofing, and then click AutoCorrect Options.

In the AutoCorrect dialog box, do the following:

Click the AutoFormat As You Type tab, and under Replace as you type, select or clear the "Straight quotes" with “smart quotes” check box.

Click the AutoFormat tab, and under Replace, select or clear the "Straight quotes" with “smart quotes” check box.

oh if you must:

<?php 

function convert_smart_quotes($string) 
{ 
$search = array(chr(145), 
                chr(146), 
                chr(147), 
                chr(148), 
                chr(151)); 

$replace = array("'", 
                 "'", 
                 '"', 
                 '"', 
                 '-'); 

return str_replace($search, $replace, $string); 
} 

?>

alternative replace to keep them for people like David Harkness

<?php 

$replace = array('&lsquo;', 
             '&rsquo;', 
             '&ldquo;', 
             '&rdquo;', 
             '&mdash;'); 

?>


You will want to make sure your server is sending the UTF-8 character set on the Content-Type header. The curly quotes use more than one byte so you need an appropriate charset to reflect that. If your server is not sending the charset in the header, most browsers will assume you are using the standard ISO-8859 charset that only uses one byte per character which would show in that you are getting 3 characters from only one character that you inputted.

If you use Apache, you should set your default character set like so in the httpd.conf:

AddDefaultCharset UTF-8

If you do not have access to your server configuration, you can send a header from php before any content is outputted.

header('Content-Type: text/html; charset=UTF-8');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜