<?php /* 字体转换 $content 内容 $to_encoding 目标编码,默认为UTF-8 $from_encoding 源编码,默认为GBK */ function mbStrreplace($content,$to_encoding="UTF-8",$from_encoding="GBK") { $content=mb_convert_encoding($content,$to_encoding,$from_encoding); $str=mb_convert_encoding(" ",$to_encoding,$from_encoding); $content=mb_eregi_replace($str," ",$content); $content=mb_convert_encoding($content,$from_encoding,$to_encoding); $content=trim($content); return $content; } ?> PHP将全角空格转成半角, 并去除头尾空格 1.将GBK字符串转成 UTF-8, 2.将全角空格转成UTF-8 3.将替换后的字符串改成GBK 4.去除头尾空格 5.返回字符串