Good morning everyone. I am seeking to expand my knowledge of PHP. This morning I am working on a lesson for files and directories in Larry Ulman’s book, “PHP For The World Wide Web!”
The script is as follows:
<html>
<head>
<title>Using Files</title>
</head>
<body >
<?php
function WriteToFile ($URL, $Description) {
/* Function WriteToFile takes two arguments–URL and Description–which wil be written to an external file.
$TheFile = “data.txt”;
$Open = fopen($TheFile, “a”);
if ($Open) {
fwrite($Open, “$URLt$Descriptionn”);
fclose($Open);
$Worked = TRUE;
} else {
$Worked = FALSE;
}
return $Worked;
}
// End of WriteToFile Function
function ReadFromFile() {
/*Function ReadFromFile displays all the information stored in an external file.
$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=”urls.php” method=post>n”);
print (“URL <input type-text name=”Array[URL]” size=60><br>n”);
print (“Description <textarea name=”Array[Description]” rows=5 cols=40></textarea><br>n”);
print (“<input type=hidden name=”BeenSubmitted” value=”TRUE”>n”);
print (“<input type=submit name=”submit” value=”Submit!”> </form>n”);
function HandleForm () {
global $Array;
$Pattern = “([url]http://^[:space:]]+)([[:alnum:].
if (eregi($Pattern, $Array[“URL”]))
{
$Replace = “<a href=”http://_
$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>
When I tested the script on my server, I received the following error:
Parse error: parse error in /home/iwdtests/public_html/FilesDir/urls.php on line 88
I don’t understand because line 88 is the </html>. Can someone please explain this to me?
I’ve checked and rechecked my script against that against the book and I haven’t find anything different.
As usual, your wisdom and knowledge will be greatly appreciated.
Magikey