【问题标题】:Find and Replace with QueryPath使用 QueryPath 查找和替换
【发布时间】:2012-05-25 12:22:35
【问题描述】:

我有一个分配给 $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>';

【问题讨论】:

    标签: php querypath


    【解决方案1】:

    尝试删除 html()

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

    用于展示:

    $output->writeHTML();
    

    html():: 替换当前元素的子内容或 一个 HTML 文档

    【讨论】:

    • 我还不想输出内容,我想把原来的$output改回来。我已经更新了我最初的问题。
    猜你喜欢
    • 2014-09-01
    • 2012-09-22
    • 2020-08-05
    • 2011-03-02
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    • 2019-11-29
    相关资源
    最近更新 更多