Quantcast
Channel: How to remove unwanted commas from a string? - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by Subrata Mallik for How to remove unwanted commas from a string?

<?php$str = ",a,b,c,,,d,,"echo $str=str_replace(',,','',$str);?>Output:,a,b,c,d<?php $str = ",a,b,c,,,d,,"echo $str=trim(str_replace(',,','',$str),',');?>Output:a,b,c,d

View Article


Answer by neelsg for How to remove unwanted commas from a string?

Probably not very fast, but a simple method may be:$str = "a,b,c,,,d";$str2 = "";while($str <> $str2) { $str2 = $str; $str = str_replace(',,', ',', $str);}

View Article


Answer by Fabio for How to remove unwanted commas from a string?

i think you can just explode your string and then create a new one getting only relevant data$string = ",a,b,c,,,d,,";$str = explode(",", $string);$string_new = '';foreach($str as $data){...

View Article

Answer by Matteo Tassinari for How to remove unwanted commas from a string?

Try this:$str = preg_replace('/,{2,}/', ',', trim($str, ','));The trim will remove starting and trailing commas, while the preg_replace will remove duplicate ones.See it in action!Also, as @Spudley...

View Article

How to remove unwanted commas from a string?

How can i remove duplicate commas used in string.String = ",a,b,c,,,d,,"I tried rtrim and itrim functions and removed the unwanted commas from beginning and ending .How can i remove duplicate commas ?

View Article

Browsing all 5 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>