PHP中的奇怪字符集行为的函数参数

PHP中的奇怪字符集行为的函数参数

本文介绍了PHP中的奇怪字符集行为的函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下PHP代码:

 <?php 

ini_set('default_charset ','UTF-8');
mb_internal_encoding('UTF-8');

function labelValidate($ label)
{
echo mb_detect_encoding($ label.'x','UTF-8,ISO-8859-1');

echo'< br />';

echo mb_detect_encoding('Rio,coraçãodo Brasil','UTF-8,ISO-8859-1');
}

labelValidate('Rio,coraçãodo Brasil');

?>

我得到这个输出:



ISO -8859-1
UTF-8



任何人都知道为什么参数$ label有ISO字符集,但是我在函数中创建的直接回声有UTF- 8 encode?

这会让我头痛,因为我必须在$ label var中添加一个utf8_encode,否则会在输出中产生有问题的字符。



感谢您的帮助!

解决方案

@Michael Madsen,我下载了Notepad ++(PHP IDE)并转换了没有BOM的文件UTF-8字符集,所以我的所有问题都已解决。 Dreamweaver正在将一些文件保存为ANSI,这是生成对PHP的混乱。



非常感谢所有!


i have the following PHP code:

<?php

ini_set( 'default_charset', 'UTF-8' );
mb_internal_encoding('UTF-8');

function labelValidate($label)
{
    echo mb_detect_encoding($label.'x', 'UTF-8, ISO-8859-1');

    echo '<br />';

    echo mb_detect_encoding('Rio, coração do Brasil', 'UTF-8, ISO-8859-1');
}

labelValidate('Rio, coração do Brasil');

?>

I get this output:

ISO-8859-1UTF-8

Anybody knows why the parameter $label has ISO charset, but the direct echo which i created inside the function has UTF-8 encode?

This is generating a headache to me, because i have to put a utf8_encode in $label var, otherwise i get problematic chars in the output.

Thanks for any help!

解决方案

With the help of @Marc B and @Michael Madsen, i downloaded Notepad++ (PHP IDE) and converted the file UTF-8 charset without BOM, so all my problems have been resolved. The Dreamweaver was saving some files as ANSI, this was generationg the confusion on PHP.

Many thanks for all!

这篇关于PHP中的奇怪字符集行为的函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:27