T_ENCAPSED_AND_WHITESPACE
Results 1 to 2 of 2

Thread: T_ENCAPSED_AND_WHITESPACE

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1

    T_ENCAPSED_AND_WHITESPACE

    I'm trying to create a function that builds the content of a page and adds database info at a specific point in the process. I get this error:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\EasyPHP-5.3.8.0\www\test\dukejets\view\pagecreator82812.php on line 20

    This is line 20:

    PHP Code:
    "\t\t\t echo $content = content($row['ICAO'], $row['FAA'], $row['Name'], $row['Place'], $row['State'], $row{['Country'], $row['Elevation'], $row['RunwayID'], $row['RunwayLength'], $row['RunwayWidth'] );\r" 
    Here's the entire function:

    PHP Code:
    function template($i){
        $body = "<?php\r" . 
                "
    \tinclude 'header.php';\r" . 
                "
    \tinclude 'uppercontent.php';\r"  . 
                "
    \tinclude 'functions.php';\r" . 
                "
    \tset_time_limit(130);\r" .
                "
    \t$con mysql_connect('localhost','admin','a28792879');\r" .
                    "
    \t\tif (!$con)\r" .
                        "
    \t\t\t{\r" .
                        "
    \t\t\tdie('Could not connect: ' mysql_error());\r" .
                        "
    \t\t\t}\r" .
                "
    \t$j " . $i . ";\r" . 
                "
    \tmysql_select_db('trail'$con);\r" . 
                "
    \t$query 'SELECT * FROM airports WHERE numbers = $j';\r" .
                "
    \t$result mysql_query($query) or die(mysql_error());\r" .
                    "
    \t\twhile($row mysql_fetch_array($result))\r" . 
                        "
    \t\t\t{\r" . 
                        "
    \t\t\echo $content content($row['ICAO'], $row['FAA'], $row['Name'], $row['Place'], $row['State'], $row{['Country'], $row['Elevation'], $row['RunwayID'], $row['RunwayLength'], $row['RunwayWidth'] );\r" .
                        "
    \t\t\t$id $row['ID'];\r" .
                        "
    \t\t\t}\r" .
                "
    \t$query2 'SELECT * FROM fbo WHERE AirportID=$id';\r" .
                "
    \t$result2 mysql_query($query2) or die(mysql_error());\r" .
                    "
    \t\twhile($row2 mysql_fetch_array($result2))\r" .
                        "
    \t\t\t{\r" .
                        "
    \t\t\techo $content2fboContent($row2['Name'], $row2['Email'], $row2['Address1'], $row2['Website'], $row2['Address2'], $row2['City'], $row2['ZipCode'], $row2['Country'], $row2['Phone1'], $row2['Phone2']);\r" .
                        "
    \t\t\t}\r" .
                "
    \tinclude 'lowercontent.php';\r" .        
                "
    \tinclude 'footer.php';\r" . "?>";
        return $body;
      }

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,541
    PHP gets confused by quoted array keys within a double-quoted string literal. I recommend either using complex (curly braces) notation or concatenation, e.g.:
    PHP Code:
    $string "foo {$array['key']} bar";
    $anotherString "foo ".$array['key']." bar"
    Alternatively (but I think makes for messy code, in that it's inconsistent with array keys not in a string literal), this will work, too:
    PHP Code:
    $yuck "foo $array[key] bar"// note no quotes around array key 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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