Reputation: 4349
I'm trying to add a space after each output but its only appearing on the last output
if ($en['mm_wmeet']) {
$tmp = explode(",", $en['mm_wmeet']);
for ($i = 0; $i < count($tmp); $i++) {
$en['mm_wmeet'] = $tmp[$i]. " ";
}
}
Upvotes: 0
Views: 5298
Reputation: 339816
The net effect of what you're doing is to just replace the commas with spaces, so you can use PHP's built-in str_replace
function:
$en['mm_wmeet'] = str_replace(',', ' ', $en['mm_wmeet']);
If your search string was more complicated, you could use a regular expression instead.
For example if you wanted to also strip out any existing plain white space between the list items, you could use this:
$en['mm_wmeet'] = preg_replace('/,\s*/', ' ', $en['mm_wmeet']);
If you really want an additional trailing space after that, just append it.
Upvotes: 1
Reputation: 5664
best method is str_replace()
$en['mm_wmeet'] = str_replace(',', ' ', $en['mm_wmeet']);
Upvotes: 4
Reputation: 12537
As Pekka said, use either .=
:
$tmp = explode(",", $en['mm_wmeet']);
for ($i = 0; $i < count($tmp); $i++) {
$en['mm_wmeet'] .= $tmp[$i] . " ";
}
Or alternatively, use implode
:
$tmp = explode(",", $en['mm_wmeet']);
$en['mm_wmeet'] = implode(" ", $tmp);
Upvotes: 6