dongyi8795 2014-07-01 14:30
浏览 19
已采纳

从php字符串中删除短语

I'm building a website in Wordpress and wish to have a list of catogories on a seperate page which acts as a filter for the isotope plugin. So far i've managed to get this working however i now need to remove the phrase "academia" from each category as this is can only be seen in the backend of wordpress but when trying to use str_replace it doesn't render any results.

Is anyone kind enough to some help? :)

link to website : http://www.bluemoontesting.co.uk/intbauwp/testing/#

<?php

    $terms = get_categories('orderby=name&depth=1&title_li=&use_desc_for_title=1&parent=34');  // get all categories, but you can use any taxonomy
    $remove = str_replace("academia","", $terms);
    $count = count($remove); //How many are they?


    if ( $count > 0 ) {  //If there are more than 0 terms

        foreach ( $terms as $term ) 

        {  //for each term:
            echo "<li><a href='#' data-option-value='.".$term->slug."'>" . $term->name . "</a></li>
";
            //create a list item with the current term slug for sorting, and name for label
        }
    }
?>
  • 写回答

2条回答 默认 最新

  • dooso0594 2014-07-01 14:35
    关注

    Add str_replace in foreach.

    $name = str_replace("academia","", $term->name);
    

    Like this :

    if ( $count > 0 ) {
        foreach ( $terms as $term ) {
            $name = str_replace("academia","", $term->name);
            echo "<li><a href='#' data-option-value='.".$term->slug."'>" . $name . "</a></li>
    ";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效