CS174
Chris Pollett
Sep 19, 2022
php name_of_script.php #runs name_of_script.php php -a # run in enter interactive mode. will get a prompt... php > echo "hello world"; hello world php > quit cd ~/public_html php -S localhost:8000 #starts built-in web server on port 8000 # using current dir as document root
short_open_tag = Onso that you can escape to a PHP script using <? rather than <?php
;error_reporting = E_ALL & ~E_NOTICEand uncomment it, restart Apache.
Which of the following is true?
$bob = 6; echo "Bob=$bob"; // outputs Bob=6 echo 'Bob=$bob'; // outputs Bob=$bob
<p> A paragraph. Let's hop into interpretive mode: <?php print "hi there"; ?> back to copy mode </p>
<p> A paragraph. Let's hop into interpretive mode to echo the variable $foo: <?= $foo ?> back to copy mode </p>
$a = "hello"; //Heredocs $str = <<<EOD This string that lives on multiple lines uses heredocs syntax. $a interpolation happens EOD; echo $str; //Nowdocs $str2 = <<<'EOD2' $a interpolation doesn't happens EOD2; echo $str2;
<?php ob_start(); ?> <p>Hello World</p> <?php $out = ob_get_clean(); $out = strtolower($out); echo $out;