happyhippy Posted August 31, 2011 Share Posted August 31, 2011 foreach($html->find('a') as $element) echo $element->href . '<br>'; I understand that the code above results in printing out all links on the page in text. I want the same but only in a <div> I choose. See below: <div id=web> <A href = myweb.com/url1>home</a> <A href = myweb.com/url2>about</a> <A href = myweb.com/url3>contact</a> </div> I want for example <div id=web> to print out onto page the urls in plain text from within that <div> or put into an array so I can create variables out of each url to do different actions. I'm using simple html dom I've tried different ways but I either get an error, a blank white page, or a print out of the word array? Either direct me to some web sources or write a code out for me, thanks Link to comment https://forums.phpfreaks.com/topic/246089-gathering-print-outs-of-url-links-in/ Share on other sites More sharing options...
voip03 Posted August 31, 2011 Share Posted August 31, 2011 You need CSS #web { font-family:"trebuchet ms", verdana, sans-serif; font-size:12px; font-weight:bold; position:absolute; height:27px; top:60px; left:0px; width:100%; padding:0px; color:#FFFFFF; background-color:#eee; } Link to comment https://forums.phpfreaks.com/topic/246089-gathering-print-outs-of-url-links-in/#findComment-1263819 Share on other sites More sharing options...
happyhippy Posted August 31, 2011 Author Share Posted August 31, 2011 no I want to scrape the a href urls out of the <div> on the page and print the urls as plain text as a result or store them in an array. Link to comment https://forums.phpfreaks.com/topic/246089-gathering-print-outs-of-url-links-in/#findComment-1263872 Share on other sites More sharing options...
WebStyles Posted August 31, 2011 Share Posted August 31, 2011 Something like this? preg_match_all('/\<div id=web\>(.*?)\<\/div\>/is', $page, $matches); where $page contains the whole page's code. $matches will be created as an array containing the results. (not sure if you also need to escape the = sign). Link to comment https://forums.phpfreaks.com/topic/246089-gathering-print-outs-of-url-links-in/#findComment-1263924 Share on other sites More sharing options...
samshel Posted August 31, 2011 Share Posted August 31, 2011 Try this : foreach($html->find('div[id=web]') as $div) { foreach($div->find('a') as $element) { echo $element->href . '<br>'; } } //OR $div = $html->find('div[id=web]'); foreach($div->find('a') as $element) { echo $element->href . '<br>'; } Link to comment https://forums.phpfreaks.com/topic/246089-gathering-print-outs-of-url-links-in/#findComment-1264083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.