php 按符号截取中文字符串,gb2312不乱码如:星座_单选
要求:截取_之前的中文
效果:星座$a="星座_单选";
……
echo $a;

解决方案 »

  1.   

    <?php  
    $str='星座_单选';
    preg_match('/(.*)_/iU',$str,$matches);
    echo $matches[1];
      

  2.   

    $str='星座_单选';
    $str=substr($str,0,stripos($str,'_'));
    echo $str;
      

  3.   

    在问一个相关问题2楼和3楼$str='星座_单选';能在给出一个,判断_之后中文字符的吗 并且判断值为单选时$value=1
      

  4.   


    基本就是一下的效果:
    $a="星座_单选";……截取_之后的中文echo $a;if($a == "单选"){$b ==1;} 
      

  5.   

    $a="星座_单选";
    $arr=explode('_',$a);
    print_r($arr);  
      

  6.   

    string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )
    php5.3新增可选的 before_needle 参数。echo strstr('星座_单选','_',true);//php5.3有效
      

  7.   

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    $str="星座_单选";
    $arrstr=explode("_",$str);echo $arrstr[0];

    <meta http-equiv="Content-Type" content="text/html;charset=gb2312">
    $str="星座_单选";
    $arrstr=explode("_",$str);
    echo iconv("UTF-8","GB2312",$arrstr[0]);echo iconv("GB2312","UTF-8",$arrstr[0]);
      

  8.   

    $str='星座_单选';
    $str=substr($str,strripos($str,'_')+1);
    echo $str;单选