Jump to content

Grabbing DIV Tags


Stotty

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.