【问题标题】:% symbol is not displayed through% 符号不通过显示
【发布时间】:2013-10-08 18:02:21
【问题描述】:

我有这个用于里程碑式 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');

现在,当我添加“data-perc”属性 99% 时,会显示一个奇怪的文本,例如:

<span class="milestone-count highlight">NaN</span>

如果我只添加像 99 这样的数字,则输出是正确的:

 <span class="milestone-count highlight">99</span>

如何在此处的 count 变量后面附加 % 符号:

$rnr_milestone_box .= '<span class="milestone-count highlight">'. $count .'</span>';

谢谢!

【问题讨论】:

  • data-perc 的值是多少? $count 变量是什么?请...真的read the notes,并且不要使用extract
  • 尝试在 $count 后附加 % 符号..
  • 您是说在 $rnr_milestone_box 中附加 % 符号;变量?
  • 我认为我没有正确附加,因为没有显示它,你能给我一个正确的附加例子吗?

标签: php html wordpress symbols


【解决方案1】:

试试这个最佳选项:

<?php
$count = "99%";
echo htmlentities($count);
// output: 99%
?> 

谢谢。

【讨论】:

  • 你能给我一个关于我实际代码结构的例子吗?我已经尝试过了,但它不起作用。可能是因为我没有正确添加它
  • 在你的代码中使用这个'。 htmlentities($count) .'
  • 但是我应该把 echo htmlentities 放在哪里?我已经用代码更新了我的问题,请看一下并告诉我它是否正确
  • $rnr_milestone_box .= ''。 htmlentities($count) .'';
猜你喜欢
  • 1970-01-01
  • 2011-10-27
  • 2010-12-15
  • 2020-12-04
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多