PHP解析XML内容而不循环超链接

PHP解析XML内容而不循环超链接,php,Php,我有一个如下结构的xml文件: <channel> <title>abc</title> <link>domain.com</link> <description>Bla bla.</description> <item> <title>xyz </title> <link>domain.com/</link> <descriptio

我有一个如下结构的xml文件:

<channel>
 <title>abc</title>
 <link>domain.com</link>
 <description>Bla bla.</description>
<item>
  <title>xyz </title>
  <link>domain.com/</link>
<description>
  <table border="1" width="100%"><tr><th colspan="2"></th><th>P</th><th>W</th><th>D</th><th>L</th><th>GF</th><th>GA</th><th>Dif</th><th>Pts</th></tr><tr><td width="7%">1</td><td width="27%"><a target="_blank" href="domain[dot]com/new-york/"/>New York</td><td width="7%"><center>12</center></td><td width="7%"><center>8</center></td><td width="7%"><center>2</center></td><td width="7%"><center>2</center></td><td width="7%"><center>17</center></td><td width="7%"><center>10</center></td><td width="7%"<center>+7</center></td><td width="7%"><center>26</center></td></tr><tr><td width="7%">2</td><td width="27%"><a target="_blank" href="domain[dot]com/lon-don/"/>London</td><td width="7%"><center>12</center></td><td width="7%"><center>6</center></td><td width="7%"><center>4</center></td><td width="7%"><center>2</center></td><td width="7%"><center>22</center></td><td width="7%"><center>12</center></td><td width="7%"><center>+10</center></td><td width="7%"><center>22</center></td></tr></table><br/>
</description>
但是,它还包括
表数据
/
数组值
中的超链接,这些值在输出时是
域[dot]com/newyork/
域[dot]com/london/

我希望
排除输出中的超链接
,这意味着我只需要纯文本,例如
london
newyork
等等

请不要在输出中添加超链接


谢谢,

因为您刚刚在XML中显示了整个表

$html = $descXML->table->asXML();
这包含了表的所有标记,如果您只需要一些表数据,那么您需要做的是进一步处理它以提取该数据

$xml = simplexml_load_file($url);
foreach($xml->item as $item){

     $desc = html_entity_decode((string)$item->description);
     $descXML = simplexml_load_string('<desc>'.$desc.'</desc>');
     // Loop over each row of the table
     foreach ( $descXML->table->tr as $row ) {
        // If there are td elements
        if ( isset($row->td) )  {
            // Extract the value from the second td element, convert to a string and trim the result
            $html = trim((string)($row->td[1]));
            $html .= "<hr />";
            echo $html;

        }
    }
}
$xml=simplexml\u加载文件($url);
foreach($xml->item as$item){
$desc=html\u entity\u decode((字符串)$item->description);
$descXML=simplexml_load_字符串('.$desc.'');
//在表格的每一行上循环
foreach($descXML->table->tr as$row){
//如果有td元素
如果(isset($row->td)){
//从第二个td元素中提取值,转换为字符串并修剪结果
$html=trim((字符串)($row->td[1]);
$html.=“
”; echo$html; } } }
如果您想要所有的
XML,除了
标记,您可以取消设置它(假设它总是在那里)

foreach($descXML->table->tr as$row){
//如果有td元素
如果(isset($row->td)){
未设置($row->td[1]->a);
$html=$row->asXML()。“
”; echo$html; } }
因为
元素似乎保存着HTML数据-如果我们使用
$HTML\u arr=(explode(“,$HTML)),可能最好不要使用像
@CD001这样的过时的标记//放入数组print\r($html\u arr),我们会看到它是这样的。你为什么要爆炸它?您正在将其放入解析器(SimpleXML)中,因此不需要处理任何字符串操作…@CD001好的,那么请忘记
explode
函数。只要回到
echo$html
本身,请帮助我排除
链接
。谢谢,谢谢。如果我们需要所有td元素,但只需要第二个没有
链接的元素怎么办?顺便说一句,foreach循环应该如下所示:
foreach($xml->**channel**->item as$item){…
$xml = simplexml_load_file($url);
foreach($xml->item as $item){

     $desc = html_entity_decode((string)$item->description);
     $descXML = simplexml_load_string('<desc>'.$desc.'</desc>');
     // Loop over each row of the table
     foreach ( $descXML->table->tr as $row ) {
        // If there are td elements
        if ( isset($row->td) )  {
            // Extract the value from the second td element, convert to a string and trim the result
            $html = trim((string)($row->td[1]));
            $html .= "<hr />";
            echo $html;

        }
    }
}
     foreach ( $descXML->table->tr as $row ) {
        // If there are td elements
        if ( isset($row->td) )  {
            unset($row->td[1]->a);
            $html = $row->asXML(). "<hr />";
            echo $html;

        }
    }