Remove empty places in comma separated list with preg_replace
This is how you can remove empty places in a comma separated list e.g when you have a list like "one, , two, , three, , " and you want it to look like "one, two, three"
<?php
$input = "one, , , two, ";
//$input = ", two, two, ";
//$input = ", two, two";
$input = preg_replace( "/, , |, $|^, /", "", $input);
echo $input;
?>
Knowledge keywords: