Perl to PHP. Opening Files.
Posted: Tue Nov 12, 2002 1:56 pm
Hello,
I need to do this:
Opens: map.txt
this contains a list of numbers from 1-1020
foreach number Opens: /map/$NUMBER.txt
then it decides which image to print based on the contents of $number.txt
e.g if it's your userid in line1 it will print a blue block.
Now, i have never written a PHP script before, but i do write Perl Scripts. I can do it in Perl, but it takes up far to much resources. So my host suggested this place, and to use PHP. This is the script in Perl:
Any ideas in PHP? REMEMBER IT MUST USE LOW RESOURCES!
I need to do this:
Opens: map.txt
this contains a list of numbers from 1-1020
foreach number Opens: /map/$NUMBER.txt
then it decides which image to print based on the contents of $number.txt
e.g if it's your userid in line1 it will print a blue block.
Now, i have never written a PHP script before, but i do write Perl Scripts. I can do it in Perl, but it takes up far to much resources. So my host suggested this place, and to use PHP. This is the script in Perl:
Code: Select all
open (ALL, "+<$olduserlinesї10]/land/all.txt");
$lockfail = &lock("ALL");
if ($lockfail)
{
print("Error opening the landfile.\n");
}
@accounts = <ALL>;
close (ALL);
print("<table width=369 BORDER=0 CELLSPACING=0 CELLPADDING=0 bgcolor=black> <tr><td>\n");
foreach $accounts (@accounts)
{
chop $accounts if ($accounts =~ /\n$/);
open (ALLY10, "+<$place/land/$accounts.txt");
$lockfail = &lock("ALLY10");
if($lockfail)
{
}
@userlines = <ALLY10>;
close (ALLY10);
foreach $userlines (@userlines)
{
chop $userlines if ($userlines =~ /\n$/);
}
#GET THE IMAGE COMMANDS
if($userlinesї0] eq $userid)
{
$imageoutput = "blue";
}
if($userlinesї0] ne $userid)
{
$imageoutput = "mapred";
}
if($lockfail)
{
$imageoutput = "black";
}
print("<font color=WHITE face="Arial Narrow" size=-7><a href=zoom.cgi?$accounts><img src="$imagedir/$imageoutput.gif" border=0></a>\n");}