Jump to content


Photo

Unexpected $ parse error and <<<__HTML_END


  • Please log in to reply
7 replies to this topic

#1 philicious

philicious
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 05:00 PM

Hello,

I have recently loaded php-5.1.4 on my mac osx and am having trouble with most of the pages that used to work fine on external servers (dreamhost, etc).  I feel like I have narrowed it down to my usage of <<<__HTML_END.  Here is an example:

<?php
echo <<<__HTML_END
<html> 
<head></head>
<body>
<p>HELP I NEED CONTENT</p>
</body>
</html>
__HTML_END;
?>

If I view this page I get this error:

Parse error: parse error, unexpected $ in /Library/WebServer/Documents/Internestcollective/test_HTML_END.php on line 9

Is there something I am missing?  Do I need to change something in my php.ini?  Have I not loaded php-5.1.4 correctly (perhaps a question for a different forum)?


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:02 PM

Code runs fine for me. Make sure you have no spaces or anyoyther text/whitespace before or after __HTML_END;

#3 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 19 September 2006 - 05:05 PM

Yes, this works fine for me to..

#4 philicious

philicious
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 05:15 PM

Are you all running php5?

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:17 PM

I am. However it doesnt matter which version you use as PHP4 and PHP5 supports Heredoc syntax.

#6 philicious

philicious
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 05:22 PM

Is there anything in the php.ini that you can change to support Heredoc syntax?

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:32 PM

No it is bultin into the core of PHP. Did you try my suggestion by checking for any whitespace before and after __HTML_END;. it is important nothing else is on the same line than __HTML_END;

#8 philicious

philicious
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 06:23 PM

Whitespace was the problem, but it was due to my editor. 

I am using dreamweaver and I changed the Line Break Type (under Preferences >  Code Format) to LF (Unix) from CF (Macintosh). 

Like I mentioned before, I had just recently loaded php5 onto my computer and prior to that had just used external servers (Dreamhost, 1&1, etc.) to do my programming. 

Here's a good bit of info:

Most HTML editing programs on the Mac OS operating system use "MacIntosh Line Breaks" in order to be compatible with older Mac OS's. However, in order to use "heredoc" with PHP on a Mac OS it must be saved with "Unix Line Breaks". Macintosh (CR) inserts a carriage return character and Unix (LF) inserts a line feed character. You need line feed characters in order for "heredoc" to work.

If you're using Adobe GoLive 7.0:

1. In the program menu go to GoLive>Web Settings
2. In the pop-up menu where it says, "Line Break Character" select Unix (LF) from the select box and close the pop-up.

Note: Once you do this with GoLive you have to create a New document and add "heredoc" to it because this setting only applies to newly created files in the program.

If you're using BBEdit on Mac OS X:

1. In the program menu go to File > Save As
2. Select "Options" at the bottom of the pop-up window
3. Change the "Line Breaks" select box from "MacIntosh" to "Unix" and then save the file. If you've coded it correctly it will now work.


here is the whole thread:

http://www.kcpug.org...90aba12374bc738




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users