php - Check if a String has two or more commas and remove additional commas -


this question has answer here:

i've following string in database column named "alerts"

$string = '1,2,,3,4,5,,,6'; 

how go checking if string has 2 or more commas in between numbers , how remove additional commas make string this;

$string = '1,2,3,4,5,6'; 

use code :

$string = '1,2,,3,4,5,,,6'; $arr=explode(",",$string); $string=implode(",",array_filter($arr)); 

or, in 1 line

$string = implode(",",array_filter(explode(",",$string))); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -