刪除逗號我有一個像PHP變量:插入HTML標籤和PHP變量
$biling_cycles = 'Monthly,Annually';
我希望它是:
$biling_cycles = '<span> Monthly, </span> <span> Annually </span>';
刪除逗號我有一個像PHP變量:插入HTML標籤和PHP變量
$biling_cycles = 'Monthly,Annually';
我希望它是:
$biling_cycles = '<span> Monthly, </span> <span> Annually </span>';
下面的代碼爲我工作:
<?php
$biling_cycles = 'Monthly, Annually';
$cycles = explode(', ', $biling_cycles);
foreach($cycles as $cycle):
echo '<span>';
echo $cycle;
echo "</span>";
endforeach;
?>
如下你可以這樣做:
$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;
結果是:<span> Monthly </span>,<span> Annually </span>
按照這些簡單的步驟:
$biling_cycles = 'Monthly, Annually';
$cycles = explode(', ', $biling_cycles);
$span_added = "";
foreach($cycles as $cycle){
$span_added = $span_added+"<span>"+$cycle+"</span>, ";
}
echo $span_added;
輸出:
<span> Monthly </span>,<span> Annually </span>