Simply use implode and explode along with array_filter like as
$var = "User list 1,,User list 3,User list 4,,,,User list 5,,,User list 6";
echo implode("<br>",array_filter(explode(',',$var)));
Output :
User list 1
User list 3
User list 4
User list 5
User list 6
Edited :
Lets make it more clear stepwise
Step 1
We'll exploding string at , using explode function of PHP like as
explode(',',$var);
which'll result into
Array
(
[0] => User list 1
[1] =>
[2] => User list 3
[3] => User list 4
[4] =>
[5] =>
[6] =>
[7] => User list 5
[8] =>
[9] =>
[10] => User list 6
)
Now we've empty values within array. So we need to remove that empty values using array_filter like as
array_filter(explode(',',$var));
results into an array
Array
(
[0] => User list 1
[2] => User list 3
[3] => User list 4
[7] => User list 5
[10] => User list 6
)
Now as OP stated output must break at new line we'll simply use implode along with <br> like as
echo implode("<br>",array_filter(explode(',',$var)));
Results
User list 1
User list 3
User list 4
User list 5
User list 6
Demo
Explanation :
Your attempt
echo str_replace(",","<br>",$var);
What you were doing over here is replacing each ,(comma) along with <br> which'll simply output your result.
,in your string that's the problem here.