开发者

Why are there � on my page

开发者 https://www.devze.com 2023-04-13 07:37 出处:网络
I\'ve already set my page default charset and MySQL table charset utf8. It works well on some of the pages, but on some pages when output some certain Chinese characters like \'全\' and \'公\' it appe

I've already set my page default charset and MySQL table charset utf8. It works well on some of the pages, but on some pages when output some certain Chinese characters like '全' and '公' it appears to be � while on other pages they can be output normally.

The only difference between the normally pages and the error pages i realize is I used some ereg_replace before output on the error page.

                $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);
                }

Could these functions be the reason? Or what else could the reason be?

Update:

I found when I comment $sounds= preg_replace('/(\v|\s)+/', ' ', $sounds); it works fine, but i want to use this line to delete multiple white spaces in my data. What's the alternative way to do this?


That could very well be the reason. Use the u (UTF-8) modifier, otherwise the regular expression is likely to match only parts of some Unicode characters.

Also, I noticed you mentioned ereg_* but are using preg_*. That's good, always prefer using preg_* instead of the old, slow and deprecated ereg_* functions.


You have to add the u modifier after your pattern like this:

'/(\v|\s)+/u'

as you can see here:

http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php


You should probably use mb_ereg_replace instead of ereg_replace.

0

精彩评论

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