Stotty Posted May 8, 2009 Share Posted May 8, 2009 Im trying to grab <div class"newsTitle"> From runescape.com How would i make it appear on my homepage my homepage is php can someone give me the code Thanks in advanced Stotty Link to comment https://forums.phpfreaks.com/topic/157393-grabbing-div-tags/ Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 I believe cURL is what you want. Link to comment https://forums.phpfreaks.com/topic/157393-grabbing-div-tags/#findComment-829693 Share on other sites More sharing options...
Stotty Posted May 8, 2009 Author Share Posted May 8, 2009 Ive already been given that url but can someone give me the code because i dont understand it Link to comment https://forums.phpfreaks.com/topic/157393-grabbing-div-tags/#findComment-829735 Share on other sites More sharing options...
thebadbad Posted May 8, 2009 Share Posted May 8, 2009 Since it's pretty straightforward, I'll give you an example. You can use file_get_contents() if you've got allow_url_fopen set to On in your server settings: <?php //set user agent string ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10'); //load website source code $source = file_get_contents('http://runescape.com/'); preg_match_all('~<div class="newsTitle">\s*<h3>([^<]+)~i', $source, $matches); //have a look at the matches in $matches[1] echo '<pre>', print_r($matches[1], true), '</pre>'; ?> Output: Array ( [0] => Bounty Hunter Wilderness-only PvP [1] => Development Diary: Tools for Games [2] => New Dwarf Quest: Diary 3 [3] => Summoning Upgrade and Hairstyles ) Link to comment https://forums.phpfreaks.com/topic/157393-grabbing-div-tags/#findComment-829776 Share on other sites More sharing options...
Stotty Posted May 8, 2009 Author Share Posted May 8, 2009 Thank you so much mate Link to comment https://forums.phpfreaks.com/topic/157393-grabbing-div-tags/#findComment-829881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.