如何通过 php 中的标记名获取值?

how can I get the value by tagnames in php?

你能给我的代码一个建议吗?

$string = "<li>CIs = <a href="http://localhost/itop/web/pages/UI.pdomhp?operation=details&class=FunctionalCI&id=49&c[menu]=ConfigManagementOverview" title="Functional CI::49">Sep Console04</a>, 42 49, Sep11, Sep Console04<br/><a href="http://localhost/itop/web/pages/UI.php?operation=details&class=FunctionalCI&id=50&c[menu]=ConfigManagementOverview" title="Functional CI::50">Sep Console05</a>, 42 50, Sep11, Sep Console05<br/><a href="http://localhost/itop/web/pages/UI.php?operation=details&class=FunctionalCI&id=53&c[menu]=ConfigManagementOverview" title="Functional CI::53">Sep Engine CO04</a>, 42 53, Sep11, Sep Engine CO04</li>";
$doc = new DOMDocument(); 
$doc->loadHtml($string);
$result_data = $doc->getElementsByTagName('li');

但是,我得不到正确的结果。谢谢大家!

此致,

安华

<li> 之前和 </li>

之后使用单引号

同时将字符串中的所有&改为&amp;,它们是需要转换为HTML的特殊字符:

$string = str_replace('&','&amp;', $string);

我觉得你很亲近

以下方法可以解决问题:

$string = '<li>CIs = <a href="http://localhost/itop/web/pages/UI.pdomhp?operation=details&class=FunctionalCI&id=49&c[menu]=ConfigManagementOverview" title="Functional CI::49">Sep Console04</a>, 42 49, Sep11, Sep Console04<br/><a href="http://localhost/itop/web/pages/UI.php?operation=details&class=FunctionalCI&id=50&c[menu]=ConfigManagementOverview" title="Functional CI::50">Sep Console05</a>, 42 50, Sep11, Sep Console05<br/><a href="http://localhost/itop/web/pages/UI.php?operation=details&class=FunctionalCI&id=53&c[menu]=ConfigManagementOverview" title="Functional CI::53">Sep Engine CO04</a>, 42 53, Sep11, Sep Engine CO04</li>';
$doc = new DOMDocument(); 
$doc->loadHtml($string);
$liList = $doc->getElementsByTagName('li');
$result_data = array();
foreach ($liList as $li) {
    $result_data[] = $li->nodeValue;
}

参见:Get ul li a string values and store them in a variable or array php