PHP简单HTML DOM解析器-查找Span ID

PHP简单HTML DOM解析器-查找Span ID,php,html,simple-html-dom,Php,Html,Simple Html Dom,我想确认某个特定的 下面是HTML的一个示例: <div class="mgrRspnInline"> <div class="header"> David, Manager at The Pub, responded to this review </div> <p class="partial_entry"> <span id="response_232376288"> Thank you for taking the time t

我想确认某个特定的 下面是HTML的一个示例:

<div class="mgrRspnInline"> <div class="header"> David, Manager at The Pub, responded to this review </div> <p class="partial_entry"> <span id="response_232376288"> Thank you for taking the time to write a review and post feedback. We appreciate your comments, hope that you continue to visit us and be satisfied every time. Looking forward to seeing you again soon </span>
$review\u id是数组中的一个review id列表,即-
response\u 232376288
,此时我希望代码执行的操作是
如果找到
response\u 232376288
,则回显Yes
,如果没有,则返回no,但我得到的只是no


如果有人能提供帮助?

是的,只要在循环中使用该
$value
作为指针,就可以使用相应的id搜索该范围:

$html_string = '
<div class="mgrRspnInline">
    <div class="header"> David, Manager at The Pub, responded to this review </div>
    <p class="partial_entry">
    <span id="response_232376288">
    Thank you for taking the time to write a review and post feedback. We appreciate your comments, hope that you continue to visit us and be satisfied every time. Looking forward to seeing you again soon
    </span>
</div>';

$html = str_get_html($html_string);
$review_id = array('response_232376288', 'response_99999999');
foreach($review_id as $value) {
    echo 'The current value is: <strong>' . $value . '</strong><br/>';
    echo 'Does it exist? <br/>';
    $span = $html->find("span#$value", 0);
    if($span != null) {
        echo 'Yes!';
    } else {
        echo 'No :) sorry';
    }
    echo '<hr/>';
}

是的,只要在循环中使用该
$value
作为指针,就可以使用相应的id搜索该范围:

$html_string = '
<div class="mgrRspnInline">
    <div class="header"> David, Manager at The Pub, responded to this review </div>
    <p class="partial_entry">
    <span id="response_232376288">
    Thank you for taking the time to write a review and post feedback. We appreciate your comments, hope that you continue to visit us and be satisfied every time. Looking forward to seeing you again soon
    </span>
</div>';

$html = str_get_html($html_string);
$review_id = array('response_232376288', 'response_99999999');
foreach($review_id as $value) {
    echo 'The current value is: <strong>' . $value . '</strong><br/>';
    echo 'Does it exist? <br/>';
    $span = $html->find("span#$value", 0);
    if($span != null) {
        echo 'Yes!';
    } else {
        echo 'No :) sorry';
    }
    echo '<hr/>';
}

让我们清理一下@ghost的答案。答案很简单:

echo $html->find('#response_232376288', 0) ? 'Yes' : 'No';

真的没有必要用一堆多余的胡说八道把这么简单的答案弄得乱七八糟*(除非你碰巧喜欢这些多余的胡说八道)

让我们把@ghost的答案清理一下。答案很简单:

echo $html->find('#response_232376288', 0) ? 'Yes' : 'No';
真的没有必要用一堆多余的胡说八道把这么简单的答案弄得乱七八糟*(除非你碰巧喜欢多余的胡说八道,我想)