note 96894 modified in language.types.string by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Jun 2010 15:11:47 +0000 |
| Subject: | note 96894 modified in language.types.string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170434@lists.php.net to get a copy of this message | ||
If you try to embed backticks (AKA backquotes) inside of a heredoc, it won't treat the
backticks as a shell command execution operator:
<?php
echo <<<_HTML_
<pre>
ls -l</pre>
_HTML_;
?>
the above example will simply output the literal string 'ls -l' rather than running the
command and outputting the results.
To interpolate shell command data you first have to store the returned backtick'd info in
variables, then place the variables inside the heredoc:
<?php
$cmd1 = ls -l;
$cmd2 = shell_exec("netstat"); // same thing as backticks
echo <<<_HTML_
<pre>$cmd1 <hr> $cmd2</pre>
_HTML_;
?>
--was--
If you try to embed backticks (AKA backquotes) inside of a heredoc, it won't treat the
backticks as a shell command execution operator:
echo <<<_HTML_
<pre>ls -l</pre>
_HTML_;
the above example will simply output the literal string 'ls -l' rather than running the
command and outputting the results.
To interpolate shell command data you first have to store the returned backtick'd info in
variables, then place the variables inside the heredoc:
$cmd1 = ls -l;
$cmd2 = shell_exec("netstat"); // same thing as backticks
echo <<<_HTML_
<pre>$cmd1 <hr> $cmd2</pre>
_HTML_;
http://php.net/manual/en/language.types.string.php