Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么会有࿽;在我的页面上_Php_Mysql_Regex_Character Encoding - Fatal编程技术网

Php 为什么会有࿽;在我的页面上

Php 为什么会有࿽;在我的页面上,php,mysql,regex,character-encoding,Php,Mysql,Regex,Character Encoding,我已经设置了页面默认字符集和MySQL表字符集utf8。它在某些页面上运行良好,但在某些页面上,当输出某些汉字时,如'全' 而且公' 似乎是� 而在其他页面上,它们可以正常输出。正常页面和错误页面之间的唯一区别是我在错误页面上输出之前使用了一些ereg_替换 $sounds = nl2br($model->sounds); $sounds= preg_replace('/(\v|\s)+/', ' ', $sounds);

我已经设置了页面默认字符集和MySQL表字符集utf8。它在某些页面上运行良好,但在某些页面上,当输出某些汉字时,如'全' 而且公' 似乎是� 而在其他页面上,它们可以正常输出。
正常页面和错误页面之间的唯一区别是我在错误页面上输出之前使用了一些ereg_替换

                $sounds = nl2br($model->sounds);
                $sounds= preg_replace('/(\v|\s)+/', ' ', $sounds);
                $sounds= preg_replace("#(<br />|<br /> )+[< b r > \  ]*[<br />| <br /> ]+#","<br>",$sounds);
                $pattern='#[\d]+[\-]*[\d]*[\.]+#';
                if(preg_match($pattern,$sounds)&&!preg_match('#<br />|<br />|<br>#',$sounds))
                {
                    $sounds= preg_replace("#[\d]+[\-]*[\d]*[\.]+#","<br>",$sounds);
                }
$sounds=nl2br($model->sounds);
$sounds=preg_replace(“/(\v|\s)+/”,“$sounds);
$sounds=preg#u replace(“#(

)+[
\]*[

]+#”,“
”,$sounds); $pattern='\[\d]+[\-]*[\d]*[\.]+\'; if(preg#u match($pattern,$sounds)和&!preg#u match(“#
|
|
#,$sounds)) { $sounds=preg\u replace(“\[\d]+[\-]*[\d]*[\.]+\\”,“
”,$sounds); }
这些功能可能是原因吗?或者还有什么原因呢


更新:
我在评论时发现,$sounds=preg\u replace(“/(\v\124;\ s)+/”,“$sounds)它工作正常,但我想用这一行删除数据中的多个空格。有什么替代方法可以做到这一点呢?

这很可能就是原因所在。使用,否则正则表达式可能只匹配某些Unicode字符的一部分


另外,我注意到您提到了
ereg.*
,但正在使用
preg.*
。这很好,总是喜欢使用
preg.*
而不是旧的、缓慢的和不推荐使用的
ereg.*
函数。

您必须在模式后添加u修饰符,如下所示:

'/(\v|\s)+/u'
正如你在这里看到的:


您可能应该使用,而不是更换。

1。ereg函数已弃用。改用preg。2.垃圾进来,垃圾出去。如果有些页面有效,而有些页面无效,那么看看这些页面之间有什么不同。或者更好的是,根本不要使用
ereg_replace
。+1-我还没有看到你在我之前几秒钟发布了正确的答案。@AurelioDeRosa感谢你的无私,在你发表评论之前,我一直在考虑采用哪个答案;)