Quick question about displaying...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

unsuaulvb
Forum Newbie
Posts: 11
Joined: Sat Nov 26, 2005 11:18 am

Post by unsuaulvb »

thing is that

Code: Select all

$path = "http://gamercard.xbox.com/$name.card";
isnt a image but a html document will it still work
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

unsuaulvb wrote:thing is that

Code: Select all

$path = "http://gamercard.xbox.com/$name.card";
isnt a image but a html document will it still work
Now we're talking! This is the kind of information you should have mentioned straight off the bat! :)

The short answer is: no, it won't work. If you want to print out the text in an HTML doc as an image, you will need to parse the HTML file and retrieve the relevant text from it. If you could post a link to an example XBox-Live card, I could help you out with the parsing.
unsuaulvb
Forum Newbie
Posts: 11
Joined: Sat Nov 26, 2005 11:18 am

Post by unsuaulvb »

foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Code: Select all

<?php

/* Open file - change path to suit your needs */
$fp = fopen('unusualvb.card', 'r');

/* Read the card file */
while ($tmp = fread($fp, 4096)) {
  $file .= $tmp;
}

/* ---Let's do the Regex dance...--- */

/* Match nick */
preg_match('@<span class="XbcFLAL">([^<]+)</span>@', $file, $matches);
$name = $matches[1];

/* Match avatar */
preg_match('@<img class="XbcgcGamertile" height="64" width="64" src="([^"]+)" />@', $file, $matches);
$avatar = $matches[1];

/* Match rep */
preg_match('@<img src="([^"]+)" />@', $file, $matches);
$rep = $matches[1];

/* Match score */
preg_match('@<span class="XbcFRAR">([\d]+)</span>@', $file, $matches);
$score = $matches[1];

/* Match zone */
preg_match('@<span class="XbcFRAR">([^<]+)</span>@', $file, $matches);
$zone = $matches[1];

/* Match game links */
preg_match_all('@<a href="(http\:\/\/live\.xbox\.com\/[\w]+-[\w]+\/profile\/Achievements\/ViewAchievementDetails\.aspx\?compareTo\=[^"]+)">@', $file, $matches);
$links = $matches[1];

/* Match game titles & icons */
preg_match_all('@<img height\="32" width\="32" title\="([^"]+)" alt\="" src="(http\:\/\/tiles\.xbox\.com\/tiles\/[\w]{2}\/[\w]{2}\/[^=]+\=\.jpg)" />@', $file, $matches);
$titles = $matches[1];
$images = $matches[2];

?>
Whew... there you go! Now put that into your GD code, and off you go! :wink:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

You can find command line tools that can create 'thumnails' of webpages, it is trivial however
unsuaulvb
Forum Newbie
Posts: 11
Joined: Sat Nov 26, 2005 11:18 am

Post by unsuaulvb »

thanks but one question do i have to position all that stuff one by one

so i have

Code: Select all

/* Open file - change path to suit your needs */
$fp = fopen('unusualvb.card', 'r');

/* Read the card file */
while ($tmp = fread($fp, 4096)) {
  $file .= $tmp;
}

/* ---Let's do the Regex dance...--- */

/* Match nick */
preg_match('@<span class="XbcFLAL">([^<]+)</span>@', $file, $matches);
$name = $matches[1];

/* Match avatar */
preg_match('@<img class="XbcgcGamertile" height="64" width="64" src="([^"]+)" />@', $file, $matches);
$avatar = $matches[1];

/* Match rep */
preg_match('@<img src="([^"]+)" />@', $file, $matches);
$rep = $matches[1];

/* Match score */
preg_match('@<span class="XbcFRAR">([\d]+)</span>@', $file, $matches);
$score = $matches[1];

/* Match zone */
preg_match('@<span class="XbcFRAR">([^<]+)</span>@', $file, $matches);
$zone = $matches[1];

/* Match game links */
preg_match_all('@<a href="(http\:\/\/live\.xbox\.com\/[\w]+-[\w]+\/profile\/Achievements\/ViewAchievementDetails\.aspx\?compareTo\=[^"]+)">@', $file, $matches);
$links = $matches[1];

/* Match game titles & icons */
preg_match_all('@<img height\="32" width\="32" title\="([^"]+)" alt\="" src="(http\:\/\/tiles\.xbox\.com\/tiles\/[\w]{2}\/[\w]{2}\/[^=]+\=\.jpg)" />@', $file, $matches);
$titles = $matches[1];
$images = $matches[2];
and

Code: Select all

<?php
$im = ImageCreate(204, 104);
$bg = imagecolorallocate($im, 0, 0, 0);
$fontcolor = imagecolorallocate($im, 255, 255, 522);
$path = "http://gamercard.xbox.com/$name.card"; 
if ( $_GET['gamertag'] == "" ) {
    $gamertag = "No Gamertag";
} else {
   $gamertag = $_GET['gamertag'];
}
////////////////////////////////////
$str = "$gamertag";
$name = str_replace(" ", "%20", $str);
$name = str_replace(".png", "", $name);
$name = str_replace(".jpg", "", $name);
$name = str_replace(".gif", "", $name);
////////////////////////////////////
ImageString  ($im, 0, 0, 0, "echo <iframe src= http://gamercard.xbox.com/$name.card scrolling=no frameBorder=0 height=140</iframe>", $fontcolor);
////////////////////////////////////
Header('Content-type: image/png');
imagepng($im);
ImageDestroy ($im);

?>
how do i put together do i have to like do each thing 1 by one
Post Reply