Jump to content

Parse error: syntax error, unexpected $end on line 71


Go to solution Solved by kicken,

Recommended Posts

To me the parse error suggests that there is a missing semi-colon or quotation something like that but I can not find a single case of not having matches.  As for the regular Expressions I know nothing so I just copied out of the book.  I have been over them several times and all seems right.  I have comments where I know that the unreconition begins. Here is the parser statement then the code.....

 

Parse error: syntax error, unexpected $end in sort_words_by_length.php on line 71. There is only 70 lines.

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Sorting words in a block of text by length</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="generator" content="Geany 0.21" />
    <link href="common.css" rel="stylesheet" type="text/css"/>
</head>

<body>
    <h1>Sorting words in a block of text by length</h1>
    <?php
        $myText = <<<END_TEXT
        But think not that this famous town has only harpooners,
        cannibals, and bumpkins to show her visitors. Not at all. Still
        New Bedford is a queer place. Had it not been for us whalemen,
        that tract of land would this day perhaps have been in as howling
        condition as the coast of Labrador.
        END_TEXT;
        
        echo "<h2>The text:</h2>";
        echo "<div style=\"width: 30em;
        \">$myText</div>";
        
        $myText = preg_replace("/[\,\.]/", "", $myText);
        $words = array_unique(preg_split("/[\n\r\t]+/",$myText));
        usort($words, create_function('$a,$b', 'return strlen($a) - strlen($b);'));
        
        
        echo "<h2>The sorted words:</h2>";
        echo "<div style\"width: 30em;
         \">";
        foreach ($words as $word) {
            echo "$word ";
            }  // Is teamed with above
            echo "</div>"; // Not sure about reconition.
    ?>   //Not gettting reconized
    
    
    <p><a href="http://httpd.apache.org/"><img src="/icons/apache_pb2.gif" alt="[ Powered by Apache ]"/></a>
</body>     //Not gettting reconized

</html>     //Not gettting reconized.  Line 70.
  • Solution

 

        $myText = <<<END_TEXT
        But think not that this famous town has only harpooners,
        cannibals, and bumpkins to show her visitors. Not at all. Still
        New Bedford is a queer place. Had it not been for us whalemen,
        that tract of land would this day perhaps have been in as howling
        condition as the coast of Labrador.
        END_TEXT;

 

HEREDOC Syntax

 

 

 

Warning

It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon ( ;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.

 

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

 

let me try this one...

 

 


...That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon.

I'm pretty sure Kicken is a hella lot better at this kind of thing than you are.

 

What is the point of asking for help if you will not listen to the answer?

Sorry I was so thick I missed the whole point. No excuse just late and tired.  I just changed the indentation and now it works.

Many thank for both of you. I guess I needed the scolding to get my attention. As for Kicken being better I am sure he is.  I am a real newbie trying to teach myself.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.