Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Brandon Stewart
3,434 PointsPHP - search page for values in divs
I have a page with this code on a different server
monday <div class="value">1</div>
Tuesday <div class="value">1123</div>
thursday <div class="value">2131</div>
friday <div class="value">1456</div>
saturday <div class="value">14</div>
I'm trying to create a php application that grabs the contents of a page, and gets all the integers inside a bunch of divs with the class "value" and adds them all up. Is this possible and what would be an easy way of doing this?
5 Answers
Erik Cruz
9,684 PointsIt is possible and you would probably want to use the 'file_get_contents' function. Enter the url of your other website that you want to parse as an argument enclosed in quotes and then you might probably want to use php's DOMDocument to parse the selected html code.
Brandon Stewart
3,434 PointsThanks Erik Cruz ! I'll look around their website documentation for a function to use
Gordon Jiroux
8,728 PointsBrandon Stewart Is this on the same page, or a different page?
Erik Cruz
9,684 PointsI have a page with this code on a different server
Gordon Jiroux
8,728 Pointsahh, you can try fopen http://php.net/manual/en/function.fopen.php then parse the return