php 按符号截取中文字符串,gb2312不乱码 php 按符号截取中文字符串,gb2312不乱码如:星座_单选要求:截取_之前的中文效果:星座$a="星座_单选";……echo $a; 解决方案 » <?php $str='星座_单选';preg_match('/(.*)_/iU',$str,$matches);echo $matches[1]; $str='星座_单选';$str=substr($str,0,stripos($str,'_'));echo $str; 在问一个相关问题2楼和3楼$str='星座_单选';能在给出一个,判断_之后中文字符的吗 并且判断值为单选时$value=1 基本就是一下的效果:$a="星座_单选";……截取_之后的中文echo $a;if($a == "单选"){$b ==1;} $a="星座_单选";$arr=explode('_',$a);print_r($arr); string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )php5.3新增可选的 before_needle 参数。echo strstr('星座_单选','_',true);//php5.3有效 <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]); $str='星座_单选';$str=substr($str,strripos($str,'_')+1);echo $str;单选 求助!!!php调用webservice出错! 用smarty的一个关于登录的问题,纠结、、、 急求php代码 为什么我的php生成的图片不显示 高手请进,有关变量提交!!! 静态页怎么进行计数??? 我下载了php-4.3.3-Win32.zip请问怎样配置? php连mssql怎么下移一条记录,怎么增加一条记录? 怎样用PHP生成gif动画或WBMP格式的动画? apache的URL重写问题 如何设置mantis1.0.8编码 如何做图片批量上传
$str='星座_单选';
preg_match('/(.*)_/iU',$str,$matches);
echo $matches[1];
$str=substr($str,0,stripos($str,'_'));
echo $str;
基本就是一下的效果:
$a="星座_单选";……截取_之后的中文echo $a;if($a == "单选"){$b ==1;}
$arr=explode('_',$a);
print_r($arr);
php5.3新增可选的 before_needle 参数。echo strstr('星座_单选','_',true);//php5.3有效
$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]);
$str=substr($str,strripos($str,'_')+1);
echo $str;单选