dongzhuo8210 2014-04-15 08:05
浏览 47
已采纳

使用str_replace将div添加到所有解析器结果

I'm using this string to get what's needed:

echo "<div id=\"lot\">".$table->children(2)->children(0)->plaintext."</div>";

And I get the result: 01 02 03 04 05 06 10 15 17 27 31 etc.

What I need is to add <div id=\"new\"></div> to each number.

<div id=\"new\">01</div> <div id=\"new\">02</div> etc etc.

I tried to use the code below but it doesn't work

 $table = $box_rezult->find("table.last-d", 0);
        $results = $table->children(2)->children(0)->plaintext;
        $string = $results;
        $var1 = str_replace(" ", "<div id=\"new\"> </div>", $string);
        echo $var1;

I would appreciate any help, thanks!

Thanks to everyone!!

  • 写回答

3条回答 默认 最新

  • doutu6658 2014-04-15 08:16
    关注

    explode() the string to an array, then implode() it:

    echo '<div class="new">' . implode('</div><div class="new">', explode(' ', $string)) . '</div>';
    

    I've changed id to class as id's must be unique.

    Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题