Home  >  Article  >  Backend Development  >  php遇到中文分割有关问题

php遇到中文分割有关问题

WBOY
WBOYOriginal
2016-06-13 12:12:18954browse

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

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

------解决思路----------------------
楼主确定是 ?
<br />$string="111 222 333";<br />echo htmlspecialchars($string);<br />

先测试一下
------解决思路----------------------
<br />$a  = "一大队 二大队 三大队";<br />$a = str_replace(' ',' ', $a);<br />$result = explode(' ', $a);<br /><br />echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';<br />echo '<pre class="brush:php;toolbar:false">';<br />print_r($result);<br />echo '
';


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

Statement:
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