Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

PHP to ignore everything until the end of the line. The second (a slash and an
asterisk) instructs PHP to ignore everything until it reaches */. The last (a
hash symbol) works like // and is included because it is common among
shell scripting languages.


This code example demonstrates the difference between // and / /:


Click here to view code image
<?php
echo "This is printed!";
// echo "This is not printed";
echo "This is printed!";
/ echo "This is not printed";
echo "This is not printed either";
/
?>


It is generally preferred to use // because it is a known quantity. It is easy to
introduce coding errors with / / by losing track of where a comment
starts and ends.


NOTE
Contrary to popular belief, having comments in your PHP script has almost
no effect on the speed at which the script executes. What little speed
difference exists is wholly removed if you use a code cache.

Escape Sequences


Some characters cannot be typed, and yet you will almost certainly want to
use some of them from time to time. For example, you might want to use an
ASCII character for a new line, but you cannot type it. Instead, you need to
use an escape sequence: \n. Similarly, you can print a carriage return
character with \r. It is important to know both of these because, on the
Windows platform, you need to use \r\n to get a new line. If you do not
plan to run your scripts anywhere other than your local Ubuntu or other Linux
environment, you need not worry about this.


Going back to the first script you wrote, recall that it printed 2010 because
you added 10 + 10 and then 10 + 0. You can rewrite that using escape
sequences, like this:


Click here to view code image
<?php
$i = 10;
$j = "10";
$k = "Hello, world";

Free download pdf