gpt4 book ai didi

php - 查找并替换为 QueryPath

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:49 25 4
gpt4 key购买 nike

我有一个字符串分配给 $output 变量。我想使用 QueryPath 遍历字符串并为每个匹配的元素添加一个类。

目前我有:

$output = qp($output)->find('table')->addclass('table')->html();

唯一的问题是它在第一次匹配之前删除了 $output 的内容。有没有一种方法可以使用 QueryPath 找到匹配项,然后添加类,同时保持 $output 的内容不变?

编辑:

Pseudo code:

$output = '<table class="temp"><blah></blah></table>';

Magic QueryPath

$output = '<table class="temp blah"><blah></blah></table>';

最佳答案

尝试删除 html()

$output = qp($output)->find('table')->addclass('table');

用于显示:

$output->writeHTML();

html():: Replaces the child content of the current element or elements in an HTML document

关于php - 查找并替换为 QueryPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10754360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com