php遇到中文分割问题

WBOY
Release: 2016-06-23 13:42:51
Original
933 people have browsed it

$a  = "一大队 二大队 三大队";
该字符串为前面处理过的字符串,空格为 
目标:将这个字符串以空格分割为三个字符串。
测试了N多种空格正则表达式,都无法使用split分割;
也使用了explode函数也没有实现,请大师帮忙解决一下。
需要PHP的解决办法。


回复讨论(解决方案)

$str = '江苏 南京 栖霞区 泰山街道';
echo $str."
";
echo $param."
";    //传进来的字符串 一大队 二大队 三大队
$s = explode(' ',$str);
print_r($s);
echo "SS".$s[0]."SS";

结果页面:
江苏 南京 栖霞区 泰山街道   //$str
一大队 二大队 三大队    //$param
Array ( [0] => 江苏 [1] => 南京 [2] => 栖霞区 [3] => 泰山街道 ) SS江苏SS

可以正常分割,切换成 $s = explode(' ',$param);
则结果页面:
江苏 南京 栖霞区 泰山街道   //$str
一大队 二大队 三大队     //$param
Array ( [0] => 一大队 二大队 三大队  ) SS一大队 炼铁厂 炼铁甲班 SS

提示: 一大队 二大队 三大队     //$param  中的空格为 

请大神帮忙看一下,如何才能正确处理  $param:      一大队 二大队 三大队   ?这个字符串肿么了????太奇怪了??

$str='一大队 二大队 三大队';$arr=explode(' ',str_replace(' ',' ',$str));print_r($arr);//Array ( [0] => 一大队 [1] => 二大队 [2] => 三大队 )
Copy after login

楼主确定是 ?

$string="111 222 333";echo htmlspecialchars($string);
Copy after login

先测试一下

$a  = "一大队 二大队 三大队";$a = str_replace(' ',' ', $a);$result = explode(' ', $a);echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';echo '<pre class="brush:php;toolbar:false">';print_r($result);echo '
Copy after login
';

Array
(
    [0] => 一大队
    [1] => 二大队
    [2] => 三大队
)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!