【问题标题】:phpQuery returning wrong results with regexphpQuery 使用正则表达式返回错误结果
【发布时间】:2014-07-20 09:23:42
【问题描述】:
    $html = '<html>
                <body>
                    <div id="dupe_1">1
                        <div class="dupe_1.1">1.1</div>
                        <div id="dupe_1.2">1.2</div>
                    </div>
                    <div id="dupe_2">2
                        <div class="dupe_2.1">2.1</div>
                        <div id="dupe_2.2">2.2</div>
                        <div>extra</div>
                    </div>
                </body>
            </html>';
    $html = phpQuery::newDocumentHTML($html);
    $node = pq('div:regex(id,^dupe_\d+$)',$html);
    echo count($node);

这将返回 7,即所有 div。它应该只返回 2 个 div(dupe_1 和 dupe_2)

【问题讨论】:

标签: regex phpquery


【解决方案1】:

我会避免做那样的事情,你应该可以用 css 得到那些:

[id*=dupe_]:not([id*="."])

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2019-10-19
    • 2016-01-22
    相关资源
    最近更新 更多