Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>getElementsByTagName</code> works on the whole document. The document has 17 <code>tr</code> elements, so it will return them all regardless where those are placed.</p> <p>As you want to look for specific <code>tr</code> elements, or more specifically for images inside a specific table, I suggest you let xpath do most of the work:</p> <pre><code>$xpath = new DOMXPath($xml); $nodes =$xpath-&gt;query("//table[@id='machine']/tbody/tr/td/div/a/img"); echo 'Found ', $nodes-&gt;length, ":\n"; foreach($nodes as $node) { $img = $node; $a = $node-&gt;parentNode; $aHref = $a-&gt;getAttribute('href'); $imgSrc = $img-&gt;getAttribute('src'); printf("Element:\n + href: %s;\n +- src: %s\n\n", $aHref, $imgSrc); } </code></pre> <p>This will list 3 elements already (not 2). You need to further on decide which ones to drop, but this should make it more easy. <a href="http://codepad.org/ogEIGM4a" rel="nofollow">Demo</a> &amp; Output:</p> <pre><code>Found 3: Element: + href: /photos.php?id=7135&amp;p=1; +- src: /class/class_Image.php?load=cGhvdG9zL0ExMTk0LmpwZ3wyNTB8MjUwfDF8 Element: + href: /photos.php?id=7135&amp;p=2; +- src: /class/class_Image.php?load=cGhvdG9zL0ExMTk0XzEuanBnfDI1MHwyNTB8MXw= Element: + href: /machine-print.php?id=7135; +- src: http://www.sterlingmachinery.com/images/quick_quote.jpg </code></pre> <p>Another tip: First normalize your data into a structure like an array. You can then use your array to generate the output. That done you can separate the parsing from the output which will make it more easy for you to achieve your goals.</p> <ul> <li>Parse the document into an array.</li> <li>Modify values as you need them in that array (e.g. <code>GetMainBaseFromURL</code>).</li> <li>Generate the output based on the array.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload