English 中文(简体)
PHP DOMDocument正在将数据从超文本中分离
原标题:PHP DOMDocument isolating data from HTML

我已尝试过两种办法,但并非如此之多的假设,所以我的html也一样:

<td>
  <a href="..?ID=343">
    <img src=".." />
  </a>
</td>
<td>
 <a href="..?id-343">  < - diffirence between two links is that this one has id in lowercase
  Some text..
 </a>
<td>

Now i want to get this element and this content: Some text..

我设法获得两种信息,但出于某种原因,如果一只印刷链接——信息一带有双重链接:

Array ( [0] => http://www.....net/2004/dealer_oglas.asp?id=5895417 [1] => http://www.....net/2004/dealer_oglas.asp?ID=5895417 [2] => http://www.....net/2004/dealer_oglas.asp?id=5883006 [3] => http://www.....net/2004/dealer_oglas.asp?ID=5883006 [4]

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "http://www.....net/2004/dealer_Zaloga.asp?dealer=12321");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);

    $dom = new DOMDocument;
    @$dom->loadHTML($output);




    // Get images
    $images = $dom->getElementsByTagName( img );
    $image_array = array();

    for($i = 0; $i < $images->length; $i++) {
        if($images->item($i)->getAttribute( width ) == "80") {
            array_push($image_array, $dom->saveHTML($images->item($i)));
        }
    }

    // Get links
    $links = $dom->getElementsByTagName( a );
    $links_array = array();
    $title_array = array();

   //Here i try to compare the two a that it finds i want to store only the one that does not have img element right after it but for some reason it stores both.

    // All arrays are the same size img, links title
    for($j = 0; $j < $links->length; $j++) {
        if(isset($image_array[$j]) && $dom->saveHTML($links->item($j+1)) != $image_array[$j]) {
            array_push($links_array,  http://www.....net/2004/  . $links->item($j)->getAttribute( href ));
            array_push($title_array, $links->item($j)->nodeValue);
        }
    }

我试图比较 no子 如果其“或“......”但又不产生任何影响,则其数值。 事先得到所有帮助。

问题回答

是否实际存在两度的联系?

<代码>$dom->getElementsByTagName(a)为global查询。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签