Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Function help..

  1. #1
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function help..

    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[URL]\" 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 = "(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>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New Coder
    Join Date
    Feb 2003
    Location
    Here
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I deleted $Array["URL"], and it works now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •