More help in parser

Everything PHP-related! Discuss scripts, host challenges, request a script, or just ask for plain old help.

Moderators: IRC Operators, Support Team

User avatar
Hobold
User
User
Posts: 60
Joined: Sun Feb 10, 2008 3:33 am
Location: Tubarão, Brazil
Contact:

More help in parser

Postby Hobold » Tue Oct 07, 2008 3:15 am

Sorry for asking too much for help.

I'm trying to make a Runehead parser, but it doesn't work and shouts a lot of errors. Can't find them, maybe because I'm new to PHP. Could anyone help me to get it to work?

Code: Select all

<?php
$data = file_get_contents("http://www.runehead.com/clans/clandb.php?sort=overall&category=1&combatType=P2P&page=1");
$x = 1;
while ($x <= 100) {
if (preg_match("<td class='tableborder'>".$x."</td>",$data)) {
$pattern = "<a href='ml.php?clan=(.*)' title='View (.*) Memberlist'>(.*)</a></td>";
preg_match($pattern, $data, $a);
$clan = explode(" ",$a);
$pattern = "<td class='tableborder'>(.*)</td>";
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$members = str_replace("</td>", "", $b);
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$combat = str_replace("</td>", "", $b);
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$hp = str_replace("</td>", "", $b);
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$magic = str_replace("</td>", "", $b);
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$ranged = str_replace("</td>", "", $b);
preg_match($pattern, $data, $a);
$b = str_replace("<td class='tableborder'>", "", $a);
$overall = str_replace("</td>", "", $b);
echo "$x $clan[4] $overall $members $combat $hp $magic $ranged";
}
$x = $x + 1;
}
?>


Page I want to print is: http://www.runehead.com/clans/clandb.ph ... P2P&page=1

Also, does anyone know where to find a parser tutorial? 'Cause I can't find one anywhere.
Image Image
slushpuppy
User
User
Posts: 873
Joined: Sun Jul 16, 2006 2:23 pm

Postby slushpuppy » Tue Oct 07, 2008 4:18 am

-
User avatar
Hobold
User
User
Posts: 60
Joined: Sun Feb 10, 2008 3:33 am
Location: Tubarão, Brazil
Contact:

Postby Hobold » Tue Oct 07, 2008 10:49 am

slushpuppy wrote:http://runehead.com/Developer+Resources-x

I know about that, but there is no version for the page I sent.
Image Image
slushpuppy
User
User
Posts: 873
Joined: Sun Jul 16, 2006 2:23 pm

Postby slushpuppy » Tue Oct 07, 2008 11:29 am

Since the data is all ordered in rank, name, type etc., you can simply do a file() of a site and create a variable with a value of 0, then everytime you encounter a <td>, echo it out then increase the variable.

Code: Select all

//example
$pointer = 0;
$map = array("rank","name","type"....);
$array = file("url...")l
foreach ($array as $plaintext) {
if (stripos($plaintext,"<td>") !== false && isset($startpos)) {
echo $map[$pointer]."$plaintext;
$pointer++;
}
if (stripos($plaintext,"unique line from which you want to start recording") !== false) {
$startpos = 1;
}
//This ensure that the $i pointer resets itself and doesn't try to seek outside the array's size
if ($pointer <= 7) {
$pointer = 0;
}
[/code]
-
User avatar
Hova
User
User
Posts: 656
Joined: Sat Oct 04, 2008 9:14 pm

Postby Hova » Tue Oct 07, 2008 12:43 pm

Hobold wrote:
slushpuppy wrote:http://runehead.com/Developer+Resources-x

I know about that, but there is no version for the page I sent.


Tell them, it'll help you and them.
Image
[url=http://my.opera.com/tobylane/affiliate]Image
<Vivec> Don't mess with toby guys; he's a professional troll.[/url]

Return to “PHP”

Who is online

Users browsing this forum: No registered users and 1 guest