【问题标题】:Getting element in PHP - PHP Simple HTML DOM Parser在 PHP 中获取元素 - PHP 简单的 HTML DOM 解析器
【发布时间】:2020-10-24 12:30:25
【问题描述】:

您能帮我解决以下问题吗? 我在 html 中有以下代码:

<div class="return-form">
                                <div class="two_cols">
                                    <div class="first_col">
                                        <label for="namesinger">Name:</label> </div>
                                    <div class="second_col">
                                        <p id="name">Axl Rose</p>
                                    </div>
                                </div>

我正在使用 PHP Simple HTML DOM Parser 库,我想在屏幕上只显示名称“Axl Rose”。

echo ($ name)

预计退出 埃克索罗斯

【问题讨论】:

    标签: php html dom


    【解决方案1】:

    这是提取数据的方法

    <?php
    // Load the HTML
    $html = str_get_html('<div class="return-form">
                                    <div class="two_cols">
                                        <div class="first_col">
                                            <label for="namesinger">Name:</label> </div>
                                        <div class="second_col">
                                            <p id="name">Axl Rose</p>
                                        </div>
                                    </di');
    
    // Locate the date via div ID and display
    echo $html->find('p[id=name]', 0)->plaintext;
    ?>
    

    更多详情Read this

    【讨论】:

    • 'div[id=name]' 应该是 'p[id=name]',因为它是 &lt;p id="name"&gt;Axl Rose&lt;/p&gt;
    猜你喜欢
    • 2015-02-19
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多