Page 1 of 1

PHP Help

Posted: Sun Feb 19, 2006 3:56 am
by Fender
I don't want a handout, but if someone could point me in the right direction, that'd be appreciated.

On a page like this:
http://ladder.guildwars.com/ladder.dll?name=war+machine
I want to parse out Rank, Rating, Wins and Loses.

I'm guessing this is fairly simple. Just a funciton name or two would be helpful. I'm looking through the function list and see many different options, but nothing is poping out to me as an obvious solution.

Posted: Sun Feb 19, 2006 4:54 am
by ^misantropia^
Have you tried regexps with preg_*? Perhaps not the fastest solution but probably the easiest.

Posted: Sun Feb 19, 2006 5:30 am
by mjrpes
here's code that seems to work:

Code: Select all

<?php

$fp = fopen ("lad.txt", "r");
$contents = fread ($fp, filesize("lad.txt"));

$pattern = "/<TR CLASS=\"ladderRankB\"><TD ALIGN=\"center\" CLASS=\"ladderRankData\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><TD ALIGN=\"center\">(.*)<\/TD><\/TR>/i";

$count = preg_match($pattern, $contents, $match);	
	
if ($count > 0)
{
	$data['Rank'] = $match[1];
	$data['Guild Name'] = $match[2]; 
	$data['Tag'] = $match[3]; 
	$data['Territory'] = $match[4]; 
	$data['Rating'] = $match[5];  
	$data['Wins'] = $match[6]; 
	$data['Losses'] = $match[7]; 
	
	var_dump($data);	
}
	
else
{
	echo "Could not Extract Contents"; 
}


?>
lad.txt is just the html of the ladder page you linked to.

Posted: Sun Feb 19, 2006 5:31 am
by mjrpes
sry, that was a handout... :(

but it was pretty simple to create code from another file i had (chuck norris fact finder :) ).

Posted: Sun Feb 19, 2006 6:25 am
by Underpants?
:J

Posted: Sun Feb 19, 2006 7:55 am
by Underpants?
somewhat related to this, does anyone know how to force ssl redirection AND a password login using php4, apache2 and/or apache-ssl?? I'm done playing the .htaccess game...

Posted: Sun Feb 19, 2006 8:59 am
by dmmh
why not use a db to store passwords then?

Posted: Sun Feb 19, 2006 12:34 pm
by Fender
Thanks mjrpes. :icon14:

Not finished yet, but here's the result

Image

Now I need to cron the page fetch every hour or so and update a local file. That and figure out how to change the font.

edit: wtf why won't that image display??? It works if you just use the URL, but not w/ the img tags. Works on other boards, just not here.

Posted: Sun Feb 19, 2006 1:05 pm
by MKJ
mjrpes wrote:sry, that was a handout... :(

but it was pretty simple to create code from another file i had (chuck norris fact finder :) ).
now to make it valid html >:E

Posted: Sun Feb 19, 2006 5:29 pm
by Underpants?
dmmh wrote:why not use a db to store passwords then?
in, say, mysql password management I've always been curious to know whether the password exchange is encrypted? Would a ssl cert exchange break anything in the php/database login? I'm a little slow in this dept. srykthnxalotbrorly

Posted: Sun Feb 19, 2006 5:34 pm
by bitWISE
Underpants? wrote:
dmmh wrote:why not use a db to store passwords then?
in, say, mysql password management I've always been curious to know whether the password exchange is encrypted? Would a ssl cert exchange break anything in the php/database login? I'm a little slow in this dept. srykthnxalotbrorly
No, SSL forms a link from the web server to the browsing client. It secures the data flow during requests from the client. PHP executes all the background tasks needed to generate the page and then sends normal HTML to the browser.

Posted: Sun Feb 19, 2006 6:25 pm
by ^misantropia^
Underpants? wrote:in, say, mysql password management I've always been curious to know whether the password exchange is encrypted? Would a ssl cert exchange break anything in the php/database login? I'm a little slow in this dept. srykthnxalotbrorly
The password is encrypted by the client, i.e. libmysqlclient, using a one-way hash (actually a challenge-response type of authentication, IIRC). As of MySQL 4.1, the protocol has been modified a bit to make it more resistant against packet sniffing or man-in-the-middle attacks.

Posted: Sun Feb 19, 2006 7:31 pm
by Underpants?
ohhh, so everything's done at the db protocol level, makes sense :icon14: thanks

Posted: Sun Feb 19, 2006 10:14 pm
by mjrpes
Fender wrote: edit: wtf why won't that image display??? It works if you just use the URL, but not w/ the img tags. Works on other boards, just not here.
q3w bb won't display images that don't end with valid extension, jpg gif png, etc. If you want to go for perfection, you can have apache treat png files as php. Create an .htaccess file in the directory you're using and put this line in it:

Code: Select all

AddType application/x-httpd-php .png
Then, rename your 'ladder.php' script 'ladder.png' and you're set.

Posted: Mon Feb 20, 2006 1:18 pm
by Fender
Thanks.

Image

Still not finished, however.

Edit: moved it to its own directory and added the .htaccess file there so it doesn't mess up png files in other directories

edit2: Also playing around w/ image creation

Create your own gradients with a URL like this
Image
http://www.fender.net/sig/gradient.png? ... est%20test
lr = left gradient red value 0 - 255
lg = left gradient green
lb = left gradient blue
rr = right gradient red
rg = right gradient green
rb = right gradient blue
w = width
h = height
fr= font red
fg = font green
fb = font blue
t = text

Posted: Tue Feb 21, 2006 3:06 am
by mjrpes