简体   繁体   中英

how do i create an array of links with simple dom and php

if($dom->load($html)){
foreach($dom->find('td.default_9 td.default_9') as $td){
  foreach($td->find('a')as $download_link){
    array_push($decklists, 'http://magic.tcgplayer.com'.$download_link->href);
      }
    }
  }

I have a td inside a td and inside the last td is a list of "a href="stuff"" ... i am creating an array of links, but i have one small issue. inside the first td is a small list (list1) of "a href="stuff"" there too. i am creating a list that has all of these 'a' tags, but would like to omit the small list (list1). i feel like there is a real simple way to only grab the inside the last td. any help would be greatly appreciated.

here is a clip of the results ... 18 and 19 are good, but 20 and 21 are from the first td.default_9

[18] => http://magic.tcgplayer.com/db/deck_search_result.asp?deck_name=Gruul Midrange&Format=Type+II&latestset=JOU
[19] => http://magic.tcgplayer.com/db/deck_search_result.asp?deck_name=American Control&Format=Type+II&latestset=JOU
[20] => http://magic.tcgplayer.com/db/article.asp?ID=11911
[21] => http://magic.tcgplayer.com/db/article.asp?ID=11909

You could only add to the array if the link contains 'deck_search_result' in the text:

if(strpos($download_link->href, 'deck_search_result') !== false){
    // array_push(...);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM