Jump to content

Recommended Posts

I am currently making a Halo 3 Player Image Generator ( http://deltadesigns.org/texasmd/generator/playerimage/ )

 

And I have been trying to find a way how they can insert the URL of some one's bungie.net profile

(heres an example of a profile: http://www.bungie.net/Stats/Halo3/Default.aspx?player=sports209 )

and get their player image off that website that they enter, and then display what parts they are using and what colors.

 

So I need to get whats between

<div class="model" ><img id="ctl00_mainContent_imgModel" src="

and

" style="border-width:0px;"/></div>

 

How would I do this?

Link to comment
https://forums.phpfreaks.com/topic/70703-getting-information-off-a-website/
Share on other sites

Indeed. You'll first need to get information from the website either with file_get_contents or with cURL (using file_get_contents() will be easier, unless specific headers need to be sent to the site).

 

As rarebit mentioned, you'll then need to find the relevant information using regular expresions.

As rarebit mentioned, you'll then need to find the relevant information using regular expresions.

 

This should be very easy as the developers have used a separate div class for the display of the image...

 

<div class="model">

 

Regards

Huggie

The following works...

 

<?php

// Set the URL
$url = 'http://www.bungie.net/Stats/Halo3/Default.aspx?player=sports209';

// Get the entire page contents
$page = file_get_contents($url);

// Match the image source
preg_match('/class="model".*?src="([^\"]+)/', $page, $matches);
$image_source = $matches[1];

// Echo the source
echo $image_source;

?>

 

Regards

Huggie

The following works...

 

<?php

// Set the URL
$url = 'http://www.bungie.net/Stats/Halo3/Default.aspx?player=sports209';

// Get the entire page contents
$page = file_get_contents($url);

// Match the image source
preg_match('/class="model".*?src="([^\"]+)/', $page, $matches);
$image_source = $matches[1];

// Echo the source
echo $image_source;

?>

 

Regards

Huggie

Alright thanks, however what is with all the extra characters that are on the preg_match function line.

Take a look at Regular Expression Syntax in the manual first, as there's a section that displays the meta-characters which may answer a lot of your questions.

 

Regular Expression Syntax is really useful to know as it's excellent for writing search routines and is used in a lot of languages, there aren't many differences between language when it comes to RegEx's

 

Regards

Huggie

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.