5 Replies - 8349 Views - Last Post: 04 November 2011 - 07:53 AM Rate Topic: -----

#1 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:21 AM

Can't even write a one-line php script!
Help
<?php		//quick_tests.php
require_once "$_SERVER['DOCUMENT_ROOT']/web/auxlib/MyErrorHandler.php"; 	
?>


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/home/.../web/auxlib/quick_tests.php on line 2

Where did I go wrong -- getting up this morning?
USIT-HI

Is This A Good Question/Topic? 0
  • +

Replies To: unexpected T_ENCAPSED_AND_WHITESPACE?

#2 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4238
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:28 AM

The way you are trying to put the document root into the string is invalid.
There are two ways to inject array elements into a string:
// First, using {...} to isolate it from the rest:
$str = "The value is: {$array['element']}.";

// Or, the "lazy" method:
$str = "The value is: $array[element].";


Was This Post Helpful? 2
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12135
  • View blog
  • Posts: 45,120
  • Joined: 27-December 08

Re: unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:28 AM

Moved to PHP. Why are you posting this in the Computer Support Forum? Please post in the appropriate forums.

If you move the $_SERVER element out of the string literal, and concatenate it with the rest of the path, that will fix it.
$_SERVER['DOCUMENT_ROOT'] . "/web/auxlib/..."


Was This Post Helpful? 1
  • +
  • -

#4 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:41 AM

Thnx for the quick response w/ explanation. Now I get

<?php		//quick_tests.php
require_once {$_SERVER['DOCUMENT_ROOT']}."/web/auxlib/MyErrorHandler.php"; 	
?>

Parse error: syntax error, unexpected '{' in /home/.../web/auxlib/quick_tests.php on line 2

Not my day!
USIT-HI
Was This Post Helpful? 0
  • +
  • -

#5 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:50 AM

Get rid of the {} around $_SERVER['DOCUMENT_ROOT']. They were there in Atli's example because the entire thing was in double quotes. You can read about that technique here, scroll down to "complex syntax" .
Was This Post Helpful? 1
  • +
  • -

#6 USIT-HI  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 14-September 11

Re: unexpected T_ENCAPSED_AND_WHITESPACE?

Posted 04 November 2011 - 07:53 AM

Got it!
<?php		//quick_tests.php
require_once $_SERVER['DOCUMENT_ROOT']."/auxlib/MyErrorHandler.php"; 	
?>


Would have had it a little earlier but discovered something strange about running this test in Mozilla Firefox.
Any changes made in Notepad++ then ftp's using File Zilla followed w/ execution using Mozilla Firefox requires two consecutive tries. Anyone encountered this?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1