I have PHP variable like:
$biling_cycles = 'Monthly,Annually';
I want it to be:
$biling_cycles = '<span> Monthly, </span> <span> Annually </span>';
You can do it as follows:
$billing_cycles = 'Monthly, Annually';
$temp = '';
foreach (explode(', ', $billing_cycles) as $key => $value) {
$temp .= "<span> $value </span>,";
}
$biling_cycles = rtrim($temp, ','); // removes trainling comma
echo $billing_cycles;
Result is: <span> Monthly </span>,<span> Annually </span>
It is not necessary to explode and iterate.
Just replace all commas with a comma, space, closing tag, space, opening tag, space. Then wrap the whole thing in an openong and closing tag.
Code: (Demo)
$billing_cycles = 'Monthly,Annually';
echo '<span> '
. str_replace(',', ', </span> <span> ', $billing_cycles)
. ' </span>';