Home > php教程 > php手册 > php中替换字符串中的空格为逗号','的方法

php中替换字符串中的空格为逗号','的方法

WBOY
Release: 2016-06-06 20:22:04
Original
1230 people have browsed it

这篇文章主要介绍php中替换字符串中的空格为逗号,的方法。感觉还不错,大家可以参考下

今天在网查到一篇介绍php中替换字符串中的空格为逗号','的文章,,作个日记保存下来。

复制代码 代码如下:


 php <br>/* <br>* 关键词中的空格替换为',' <br>*/ <br>public function emptyreplace($str) { <br>$str = str_replace(' ', ' ', $str); //替换全角空格为半角 <br>$str = str_replace(' ', ' ', $str); //替换连续的空格为一个 <br>$noe = false; //是否遇到不是空格的字符 <br>for ($i=0 ; $i<strlen>if($noe && $str[$i]==' ') $str[$i] = ','; //如果当前这个空格之前出现了不是空格的字符 <br>elseif($str[$i]!=' ') $noe=true; //当前这个字符不是空格,定义下 $noe 变量 <br>} <br>return $str; <br>} <br>?> <br>



</strlen>
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template