PHP Help

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
Fender
Posts: 5876
Joined: Sun Jan 14, 2001 8:00 am

PHP Help

Post 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.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post by ^misantropia^ »

Have you tried regexps with preg_*? Perhaps not the fastest solution but probably the easiest.
mjrpes
Posts: 4980
Joined: Tue Nov 28, 2000 8:00 am

Post 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.
mjrpes
Posts: 4980
Joined: Tue Nov 28, 2000 8:00 am

Post by mjrpes »

sry, that was a handout... :(

but it was pretty simple to create code from another file i had (chuck norris fact finder :) ).
Underpants?
Posts: 4755
Joined: Mon Oct 22, 2001 7:00 am

Post by Underpants? »

:J
Underpants?
Posts: 4755
Joined: Mon Oct 22, 2001 7:00 am

Post 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...
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post by dmmh »

why not use a db to store passwords then?
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Fender
Posts: 5876
Joined: Sun Jan 14, 2001 8:00 am

Post 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.
Last edited by Fender on Sun Feb 19, 2006 1:58 pm, edited 4 times in total.
User avatar
MKJ
Posts: 32582
Joined: Fri Nov 24, 2000 8:00 am

Post 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
[url=http://profile.mygamercard.net/Emka+Jee][img]http://card.mygamercard.net/sig/Emka+Jee.jpg[/img][/url]
Underpants?
Posts: 4755
Joined: Mon Oct 22, 2001 7:00 am

Post 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
bitWISE
Posts: 10704
Joined: Wed Dec 08, 1999 8:00 am

Post 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.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post 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.
Underpants?
Posts: 4755
Joined: Mon Oct 22, 2001 7:00 am

Post by Underpants? »

ohhh, so everything's done at the db protocol level, makes sense :icon14: thanks
mjrpes
Posts: 4980
Joined: Tue Nov 28, 2000 8:00 am

Post 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.
Fender
Posts: 5876
Joined: Sun Jan 14, 2001 8:00 am

Post 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
mjrpes
Posts: 4980
Joined: Tue Nov 28, 2000 8:00 am

Post by mjrpes »

Post Reply