Home >Backend Development >PHP Tutorial >How to replace spaces in strings with commas ',' in PHP_PHP Tutorial

How to replace spaces in strings with commas ',' in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:431048browse

Today I found an article on the Internet that introduces replacing spaces in strings with commas ',' in PHP. I made a diary and saved it.

Copy code The code is as follows:

/* 
* Replace spaces in keywords with ','
*/
public function emptyreplace($str) {
$str = str_replace(' ', ' ', $str); //Replace full-width spaces with half-width
$str = str_replace(' ', ' ', $str); //Replace consecutive spaces with one
$noe = false; //Whether encountered Characters that are not spaces
for ($i=0; $iif($noe && $str[$i]==' ') $str[$i] = ','; //If a character that is not a space appears before the current space
elseif($str[$i]!=' ') $noe=true; //Current This character is not a space. Define the $noe variable
}
return $str;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781035.htmlTechArticleI found an article on the Internet today that introduces replacing spaces in strings with commas ',' in PHP. Keep a journal and keep it. Copy the code The code is as follows: pre name="code" class="php"? php /* * Close...
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