如何修剪对象的输出 - PHP

时间:2017-11-20 23:41:16

标签: php wordpress

我正在使用带有GDrating插件的Wordpress,下面的代码(因为它)将在我的Wordpress页面上显示评级。

 if (gdrtsm_stars_rating()->loop()->has_votes()) {
                gdrtsm_stars_rating()->loop()->render()->text();
 }

此代码返回输出

  

评级:9.3。从1票。

我想从输出中修剪From 1投票部分,所以我尝试使用rtrim和substring但是效果不好。有没有办法在不干扰核心功能的情况下修剪最后的字符?

期望的输出:

  

评级:9.3。

抱歉,我无法发布所有功能。

2 个答案:

答案 0 :(得分:0)

如果它总是输出" From"部分(对不起,我对GDrating不太熟悉)你可以随时使用:

$ rating = substr($ gdr_output,0,strpos($ gdr_ouput," From"));

通过这种方式,您可以获得$ gdr_output("评分:9.3。从1票。")到" From"字符串。

答案 1 :(得分:0)

因为解决方案都没有真正操纵输出。因此,我镜像了不同名称的基函数,并修改了函数本身的字符串并调用了修改后的函数。

    if (is_null($atts['tpl_rating'])) {
        $atts['tpl_rating'] = __("Rating", "gd-rating-system").'<strong>%1$s</strong>';

        if ($atts['show_max']) {
            $atts['tpl_rating'].= '/%2$s';
        }

      //  $atts['tpl_rating'].= '.';
    }

在render.php

中评论了这个和其他一些函数
  /*
    if ($atts['show_votes']) {
        $_votes = $this->owner()->value('votes', false);

        if (is_null($atts['tpl_votes'])) {
            $render.= ' '.sprintf(_n("From %s vote.", "From %s votes.", $_votes, "gd-rating-system"), $_votes);
        } else {
            $render.= ' '.sprintf(_n($atts['tpl_votes']['singular'], $atts['tpl_votes']['plural'], $_votes, "gd-rating-system"), $_votes);
        }
    }
    */