
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Remove comma from a string in PHP?
To remove comma, you can replace. To replace, use str_replace() in PHP.
Let’s say the following is our input string with comma
$name="John,Smith";
We want the output after removing comma from the above string is
JohnSmith
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $name="John,Smith"; $result = str_replace(',', '', $name); echo "The actual value is=",$name,"<br>"; echo "After removing the comma(,)=",$result,"<br>"; ?> </body> </html>
Output
This will produce the following output
The actual value is=John,Smith After removing the comma(,)=JohnSmith
- Related Articles
- Remove new lines from string in PHP
- Remove specific word in a comma separated string with MySQL
- Stripping last comma from a foreach loop in PHP?
- PHP program to remove non-alphanumeric characters from string
- MySQL Query to remove all characters after last comma in string?
- How to create a comma separated string from a list of string in C#?
- Remove new lines from a string and replace with one empty space PHP?
- Remove Vowels from a String in Python
- Remove vowels from a String in C++
- PHP: Remove object from array
- How to create comma separated list from an array in PHP?
- How would you make a comma-separated string from a list in Python?
- What is Trailing Comma in PHP?
- PHP program to split a given comma delimited string into an array of values
- Remove Leading Zeros from a String in C#

Advertisements