...

View Full Version : Function help..



LRmaster
04-12-2003, 01:43 PM
There is a 'Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in forum1.php on line 54'. I got the script from an old php book.<html>
<head>
<title>Forum</title>
</head>
<?php
function WriteToFile ($URL, $Description) {
$TheFile = "data.txt";
$Open = fopen ($TheFile, "a");
if ($Open) {
fwrite ($Open, "$URL\t$Description\n");
fclose ($Open);
$Worked = TRUE;
} else {
$Worked = FALSE;
}
return $Worked;
}

function ReadFromFile () {
$TheFile = "data.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
print ("URLs currently listed in the data file:<p>\n");
$Data = file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode("\t", $Data[$n]);
print ("$GetLine[0]<br>\n$GetLine[1]<p>\n");
}
fclose ($Open);
print ("<hr><p>\n");
} else {
print ("Unable to read from data.txt!<br>\n");
}
} // End of ReadFromFile Function.

function CreateForm () {
/* Function CreateForm will display the HTML form. */
print ("Add a URL to the data file:\n");
print ("<form action=\"forum.php\" method=post>\n!");
print ("URL <input type=text name=\"Array\" size=60><br>\n");
print ("Description <textarea name=\"Array[Description]\" rows=5 cols=40></textarea><br>\n");
print ("<input type=hidden name=\"BeenSumbitted\" value=\"TRUE\">\n");
print ("<input type=submit name=\"sumbit\" value=\"Sumbit\"></form>\n");
} // End of the CreateForm function.

function HandleForm () {
global $Array;
$Pattern = "([url]http://)?([^[:space:]]+)([[:allnum:]\.,-_?/%=])";
if (eregi($Pattern, $Array["URL"])) {
$Replace = "<a href=\"http://\\2\\3\" target=\"_new\">\\2\\3</a>";
$Array["URL"] = eregi_replace ($Pattern, $Replace, $Array["URL"]);
$CallFunction = WriteToFile ($Array["URL"], $Array["Description"]);
if ($CallFunction) {
print ("Your submission--$Array["URL"]--has been received!<p><hr><p>\n");
} else {
print ("Your submission was not processed due to a system error!<br>\n");
}
} else {
print ("Please enter a valid Web Address!\n");
}
} // End of the HandleForm function.

/* This next conditional determines whether to handle the form, depending upon whether or not $BeenSubmitted is TRUE. */
if ($BeenSubmitted) {
HandleForm();
}
ReadfromFile();
CreateForm();
?>
</body>
</html>

Íkii
04-12-2003, 02:34 PM
I'd guess at


print ("Your submission--$Array["URL"]--has been received!<p><hr><p>\n");

that line - though as you didn't point out which line was 54 I really couldn't be bothered to copy/paste it all into a text editor just to find out.

try swapping the index defining quotes to single quotes.

LRmaster
04-12-2003, 02:40 PM
I deleted $Array["URL"], and it works now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum