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 usingpreg_*. That’s good, always prefer usingpreg_*instead of the old, slow and deprecatedereg_*functions.