Php 将数字转换为星星

Php 将数字转换为星星,php,wordpress,shortcode,rating,Php,Wordpress,Shortcode,Rating,我创建了这个将数字转换为星级的短代码。目前,短代码有效,但不完全有效: function Shortcode() { $starNumber = get_field('note_independant'); for($x=1;$x<=$starNumber;$x++) { $output .= '<i class="fa fa-star" aria-hidden="true"></i>'; } if (strpos($starNumber,',')) {

我创建了这个将数字转换为星级的短代码。目前,短代码有效,但不完全有效:

function Shortcode() {

$starNumber = get_field('note_independant');

for($x=1;$x<=$starNumber;$x++) {
    $output .= '<i class="fa fa-star" aria-hidden="true"></i>';
}
if (strpos($starNumber,',')) {
    $output .= '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
    $x++;
}
while ($x<=5) {
    $output .= '<i class="fa fa-star-o" aria-hidden="true"></i>';
    $x++;
}

return $output;

 }

add_shortcode('helloworld', 'Shortcode');
函数短码(){
$starNumber=get_字段('note_independent');
对于($x=1;$x)
  • 首先删除
    aria hidden=“true”
    以显示所有空白和半星形。了解更多信息
  • ,“
    替换为
    ”。
    以使用十进制

      if (strpos($starNumber,'.')) {
    
  • 否则,您的代码工作正常:

  • 首先删除
    aria hidden=“true”
    以显示所有空白和半星形。了解更多信息
  • ,“
    替换为
    ”。
    以使用十进制

      if (strpos($starNumber,'.')) {
    

  • 否则代码工作正常:

    问题可能取决于您使用的字体版本

    在FA 5.5中,对半星使用
    FA-FA-star-half-alt
    ,对空星使用
    far-FA-star


    问题可能取决于您使用的字体版本

    在FA 5.5中,对半星使用
    FA-FA-star-half-alt
    ,对空星使用
    far-FA-star


    您可以使用上述解决方案或WordPress星级功能


    了解更多关于wp\U star\U评级的信息

    您可以使用上述解决方案或WordPress star评级功能


    了解更多关于
    wp\u star\u rating

    您的代码在
    上有strpo,
    不是
    所以3.5在您的代码中不起作用,但是3,5会。除了3,5在PHP中作为数字无效外。我看不到代码有任何问题,除了
    /
    问题之外。
    您的代码在
    上有strpo 3,
    不是
    所以3.5在您的代码中不起作用,但3,5会起作用。除3,5在PHP中作为数字无效外,我看不出代码有任何问题,除了
    /
    问题。