sepoto Posted December 13, 2010 Share Posted December 13, 2010 Do I need to do anything to enable HEREDOC? I have some existing code that is using HEREDOC Syntax and I want to check to see if my PHP server is supporting it. I am familiar with using phpinfo();, I just don't know what to look for yet.Thanks Link to comment Share on other sites More sharing options...
Dilated Posted December 13, 2010 Share Posted December 13, 2010 Do I need to do anything to enable HEREDOC? I have some existing code that is using HEREDOC Syntax and I want to check to see if my PHP server is supporting it. I am familiar with using phpinfo();, I just don't know what to look for yet.ThanksAs far as I know, HEREDOC doesn't have to be enabled, and has been supported by php for a long time.$a = <<<ENDthis string can go on forever and contain almost anything "$';<>@$)*^&!)_*$END; That is the purpose of a HEREDOC, you could literally copy and paste just about any text into a heredoc and you then have it in string form.edit: After, brushing up on my HEREDOC understanding, apparently HEREDOC does behave like double quotes and interpolate variables and character escape codes. My mistake. Link to comment Share on other sites More sharing options...
jeffman Posted December 13, 2010 Share Posted December 13, 2010 A trick to heredocs that many people miss is that the closing delimiter (the word END in Dilated's example) MUST be typed immediately after the linebreak. No tabs, spaces, or other characters are permitted. It's counterintuitive because we have all been taught to indent code for readability. Heredoc syntax is an exception. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 13, 2010 Share Posted December 13, 2010 Does it matter what the delimiters are? I think I've seen a couple different ones used. For example:<<<HEREDOC...HEREDOC;<<<END...END;Is there a specific set of words you have to use or can you use anything like:<<<STUFF...STUFF; Link to comment Share on other sites More sharing options...
jeffman Posted December 13, 2010 Share Posted December 13, 2010 Anything.Edit. from the manual: the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 13, 2010 Share Posted December 13, 2010 Anything.Edit. from the manual:Cool. Thx! Link to comment Share on other sites More sharing options...
Fmdpa Posted December 13, 2010 Share Posted December 13, 2010 No tabs, spaces, or other characters are permitted. It's counter-intuitive because we have all been taught to indent code for readability. Heredoc syntax is an exception.If you have a problem with HEREDOCs, this is most likely the problem. It was a major point of confusion when I became familiar with HEREDOCs. edit: After, brushing up on my HEREDOC understanding, apparently HEREDOC does behave like double quotes and interpolate variables and character escape codes. My mistake.PHP 5.3.0 also supports NOWDOC, which behaves like single-quotes. The difference is that you enclose the opening delimiter in single quotes. <<<'NOW' This is a Nowdoc. It behaves like a single quote. It will print $everything literally. NOW; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.