我有这个用于里程碑wordpress短代码的PHP代码:
function rocknrolla_milestone_box_shortcode( $atts, $content = null ){
extract( shortcode_atts(array(
"count" => '90%',
"title" => ''
), $atts) );
echo htmlentities($count);
$rnr_milestone_box = '<div class="milestone-counter" data-perc="'. $count .'">';
$rnr_milestone_box .= '<span class="milestone-count highlight">'. $count .'</span>';
$rnr_milestone_box .= '<h6 class="milestone-details">'. $title .'</h6>';
$rnr_milestone_box .= '</div>';
return $rnr_milestone_box;
}
add_shortcode('milestone_box', 'rocknrolla_milestone_box_shortcode');
现在,当我添加99%的“data-perc”属性时,这会显示一个奇怪的文字,如:
<span class="milestone-count highlight">NaN</span>
如果我只添加99这样的数字,那么输出是正确的:
<span class="milestone-count highlight">99</span>
如何在计数变量后附加%符号:
$rnr_milestone_box .= '<span class="milestone-count highlight">'. $count .'</span>';
?
谢谢!
答案 0 :(得分:0)
尝试此最佳选项:
<?php
$count = "99%";
echo htmlentities($count);
// output: 99%
?>
感谢。