本帖最后由 kiqigai 于 2011-07-22 13:38:14 编辑

解决方案 »

  1.   

    还要写个类啊?
    替换utf-8中文就行了吧
    $str = '富士拍立得mini25相机';
    echo preg_replace('#[\x{4e00}-\x{9fa5}]#u',' $0 ',$str);
      

  2.   


    //a.class.php
     class Replace{
     
         private $str;
     
     function __construct($str){
        $this->str=$str;
     }
         
     function replace(){
         echo preg_replace("/[\x{4e00}-\x{9fa5}]/u",' $0 ' ,$this->str);
     }
     }
    //test.php
    include_once("a.class.php");
    $r=new Replace('富士拍立得mini25相机');
    $r->replace();富 士 拍 立 得 mini25 相 机 
      

  3.   

    echo preg_replace('/[\x80-\xff]{3}/', ' $0 ', '富士拍立得mini25相机'); 富  士  拍  立  得 mini25 相  机