Home  >  Article  >  Backend Development  >  文本替换空格成逗号解决方法

文本替换空格成逗号解决方法

WBOY
WBOYOriginal
2016-06-13 10:52:071944browse

文本替换空格成逗号
我要处理一些文本,,,这些文本不规律,有很多空白 ,我想把这些空格替换掉,但是这样又没有可读性,在删除掉空间的同时,在中间加入一个逗号,以增加可读性..

------解决方案--------------------

PHP code
$s='afdafd jjk   ddl';echo preg_replace('/\s+/',',',$s);<br><font color="#e78608">------解决方案--------------------</font><br>	$str = preg_replace('#[\r\n]+#','<br>',$str);<br>	$str = preg_replace('#\s+#',',',$str);<br><font color="#e78608">------解决方案--------------------</font><br>echo preg_replace('/\s/i', '', file_get_contents('http://www.a744.com/text.txt'));<div class="clear">
                 
              
              
        
            </div>
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