Jump to content

Archived

This topic is now archived and is closed to further replies.

448191

Simple question

Recommended Posts

I've got a simple question (Yes, I do those too  :P).

What was that thing again, whatsjemecallit, you use so you can use both single and double qoutes without having to escape them?

Something like EO>>? A link explaining what it is would be nice also.

Share this post


Link to post
Share on other sites
Wait a second? <<<EOF : "End Of File"?

How the *** does that work?

I clearly missed something basic here..  :-[

Share this post


Link to post
Share on other sites
example ok

[code]
echo <<<EOF
      <div id="main">
      {$j_main}
      </div><!--/main-->
    </div><!--/outer-->
  </body>
</html>
EOF;
[/code]

Share this post


Link to post
Share on other sites
Nevermind, I found it.

[url=http://nl2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]heredoc syntax[/url]

Share this post


Link to post
Share on other sites
does that mean according to that we can use anyold name like

<<<hithere

hithere;

Share this post


Link to post
Share on other sites
I think it does:

[quote=php.net]Another way to delimit strings is by using heredoc syntax ("<<<"). [b]One should provide an identifier[/b] after <<<, then the string, and then the same identifier to close the quotation.

The closing identifier must begin in the first column of the line. [b]Also, the identifier used 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. [/b][/quote]

Share this post


Link to post
Share on other sites
can you give an example know why use it?

what to use it on?

so on please cheers.

Share this post


Link to post
Share on other sites
it's a short cut not to use the double quotes then?

[code]
<?php
$test=<<<eof
my name is redarrow
eof;
echo $test;
?>
[/code]

Share this post


Link to post
Share on other sites
Sort of. It behaves identically to double quotes(ie expands variables), but you don't actually use double double quotes, so you can include double quotes in the string without having to escape them.

To bad there isn't an equivalent that mimics single quotes, since that's what I'd prefer. (or is there?  ::))

Share this post


Link to post
Share on other sites

×

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.