RegEx Help
Posted: Mon Jan 08, 2007 7:25 pm
feyd | Please use
Here is the contents of players.txt:
I don't understand why this is not working. The file splits fine, and I get each user's individual stats in the array $parts. The problem is that preg_match() is not working, it won't even recognize it as a valid pattern. Can someone help me fix this pattern or explain what's wrong with it? Thanks.
P.S If you havn't noticed I'm trying to parse the user stats into an array.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Here is my code:Code: Select all
$handle = fopen("players.txt", "r");
while (!feof($handle)) {
$file .= fread($handle, 1024);
}
fclose($handle);
$parts = explode("[player]", $file);
$players = array();
$index = 0;
foreach($parts as $part)
{
while (preg_match("/[(.*)](.*)[\/.*]/", $part, $match))
{
echo "test";
$players[$index][$match[1]] = $match[2];
$index++;
}
}Code: Select all
[player]
[name]john1[/name]
[kills]124[/kills]
[deaths]345[/deaths]
[/player]
[player]
[name]bob1[/name]
[kills]342[/kills]
[deaths]54[/deaths]
[/player]P.S If you havn't noticed I'm trying to parse the user stats into an array.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]