的explode function有limit
參數,你可以使用它:
<?php
// Obtain the remaining tags, if the tags count is more than 4
$totalTags = (substr_count($usr->interests, ",") + 1);
$remainingTags = $totalTags > 4 ? $totalTags - 4 : false;
// Obtain the first for 4 tags
$tags = explode(',', $usr->interests, 4-$totalTags); // (third parameter, is the limit)
// Initialize a text buffer
$textBuffer = "";
foreach($tags as $tag){
// Feed the buffer
$textBuffer .= "<span>$tag</span>,";
}
// Remove last comma
$textBuffer = substr($textBuffer, 0, strlen($textBuffer)-1);
// Insert remaining counter into the buffer
if($remainingTags){
$textBuffer = $textBuffer . " (+". $remainingTags .")";
}
// Use your variable wherever you want
echo $textBuffer;
?>
注意的爆炸Limit
參數應該是一個負數函數返回只有前4個標籤。有關更多詳細信息,請參閱上述鏈接。
*剩餘金額* - 金額,標籤? – RomanPerekhrest