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

Jul 13, 2016 am 10:28 AM
replace string space comma

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to type commas on the computer using the keyboard Detailed explanation: How to enter commas on the computer How to type commas on the computer using the keyboard Detailed explanation: How to enter commas on the computer Feb 28, 2024 am 08:34 AM

Hi, dear friends, when you use punctuation or special symbols like "--", do you still use copy and paste very cleverly? Or do I need to open word to insert symbols before typing? I will introduce to you several emergency methods when copying and pasting does not work. I hope you will like it: 1. Direct shortcut key SHIFT + "-" and use shift + the minus sign on the keyboard at the same time. You can refer to the picture above, which is common under both Mac and win systems. 2. Use in the input method: 1. Microsoft Pinyin input method (1) Use the Microsoft Pinyin input method state, click on the smiley face symbol on the far right side of the floating bar: (2) Find the symbol on the left first, and then find the punctuation on the right, as shown below You can see quotation marks or other special symbols as shown: 2. QQ Pinyin input

What does a space mean in mysql? What does a space mean in mysql? Jul 20, 2023 pm 05:17 PM

MySQL A space is a special character used to separate keywords, identifiers, values, and other statement elements. Spaces can be used in multiple locations in a SQL statement and usually do not affect the execution of the statement. The purpose of spaces: 1. Used to separate keywords and identifiers; 2. Used to separate operators and values; 3. Used to separate functions, columns and table aliases; 4. Used for indentation and alignment.

The difference between full-width spaces and half-width spaces The difference between full-width spaces and half-width spaces Mar 25, 2024 pm 12:45 PM

The difference between full-width spaces and half-width spaces. When we use word processing software or edit text content, we sometimes encounter the concept of spaces. Space is a very basic element in typesetting and formatting text, but many people may not know the difference between full-width spaces and half-width spaces. In daily use, we may feel that full-width spaces and half-width spaces have different effects in different situations, but we may not be aware of the subtle differences. First of all, the difference between full-width spaces and half-width spaces is the width they occupy.

How to replace spaces in vue How to replace spaces in vue Dec 22, 2022 am 09:40 AM

How to replace spaces in Vue: 1. Create a Vue sample file; 2. Replace all spaces through the regular expression "string = string.replace(/\s/g," ");"; 3. Through "console. log(string);" just output the replaced string.

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips Mar 28, 2024 pm 03:02 PM

PHP String Operation: Remove Extra Commas and Keep Only Commas Implementation Tips In PHP development, string processing is a very common requirement. Sometimes we need to process the string to remove extra commas and retain the only commas. In this article, I'll introduce an implementation technique and provide concrete code examples. First, let's look at a common requirement: Suppose we have a string containing multiple commas, and we need to remove the extra commas and keep only the unique comma. For example, replace "apple,ba

What is the difference between full-width spaces and half-width spaces? What is the difference between full-width spaces and half-width spaces? Mar 15, 2024 pm 03:49 PM

Differences: 1. The display width of full-width spaces is the same as that of Chinese characters, occupying two bytes. You need to use the Chinese input method when inputting, while the width of half-width spaces is half that of Chinese characters, occupying one byte, just press the space key. Can be input; 2. When typesetting text, full-width spaces make the layout more relaxed, while half-width spaces make the layout more compact.

Sharing of practical techniques for replacing spaces in Golang Sharing of practical techniques for replacing spaces in Golang Mar 13, 2024 am 09:15 AM

Title: Sharing practical techniques for replacing spaces in Golang. With the popularity and development of the Internet, program design and development have become more and more important. In the programming process, data processing is a very critical part. When processing text data, you often encounter situations where you need to replace spaces. This article will share how to implement the technology of replacing spaces in Golang and provide specific code examples. Why do I need to replace spaces? Spaces are one of the common special characters in text data. Sometimes we need to replace spaces with other characters or remove spaces.

How to use spaces correctly in Go How to use spaces correctly in Go Mar 29, 2024 pm 03:42 PM

Go language is a simple, efficient, and highly concurrency programming language. It is an open source language developed by Google. In the Go language, the use of spaces is very important, it can improve the readability and maintainability of the code. This article will introduce how to use spaces correctly in Go language and provide specific code examples. Why you need to use spaces correctly In the programming process, the use of spaces is very important for the readability and beauty of the code. Appropriate use of spaces can make code clearer and easier to read, thus reducing

See all articles