How to do a simple shell command like:
echo "Today's date is `date +%D`"
with PHP? Basically I'm looking to embed PHP library functions calls inside of PHP strings in much the same manner as above. Thanks
How to do a simple shell command like:
echo "Today's date is `date +%D`"
with PHP? Basically I'm looking to embed PHP library functions calls inside of PHP strings in much the same manner as above. Thanks
Anybody?
<?php
$date = date();
echo "Today's date is $date";
?>
Note the double quotes. PHP will evaluate the variable in strings with double quotes (not single quotes).
Using concatenation:
<? echo "Today's date is " . date("Y-m-d") . "\n"; ?>
The above (neurtrongscott's example) is how I would do it in practice....
I don't like the style of putting PHP $vars in inside strings surrounded by double quotes. It can get confusing and hard to debug in code.
What if you're reading in a large file using file_get_contents() and you want the variables in that file to be evaluated? This file would not contain PHP code.
Hmmmm.
If you are reading in a file with PHP code, and then evaluating that code, I'm not sure what you mean.
Normally, to include PHP code in a file, we use include() or include_once().
Can you paste the code and be more specific?
OK hold it. What I was looking to do before was reading in an HTML file, make transformations to it in a PHP file, then print the resultant HTML.
I didn't want to mix the HTML and PHP into the same file because I was afraid you wouldn't be able to edit the HTML/PHP hybrid file with an HTML editor like MS Word (where you edit the HTML document as if it's a word document). But it looks like I might be wrong. Looks like Word is ignoring the PHP.
Ultimately I want everything to display in a browser, and the PHP is not being ignored there which is good.
---------- Post updated at 08:13 PM ---------- Previous update was at 07:47 PM ----------
Nevermind it's not ignoring the PHP