You may not know this, but the latest version of PHP comes with avery powerful set of string manipulatation tools. This article takes anin-depth look at these tools and illustrates how they can save you time andeffort in your daily development activities.
The <<< symbol indicates to PHP that what comes next
is a multi-line block of text, and should be printed as is right up to the marker "EOF". In PHP-lingo, this is known as "here document" syntax, and it comes in very handy when you need to output a chunk of HTML code, or any other multi-line string.
Strings can be concatenated with the string concatenation operator, represented by a period(.)
// set up some string variables
$a = "the";
$b = "games";
$c = "begin";
$d = "now";
// combine them using the concatenation operator
// this returns "the games begin now"
$statement = $a . " " . $b . " " . $c . " " . $d;
// and this returns "begin the games now!"
$command = $c . " " . $a . " " . $b . " " . $d . "!";
// this also returns "begin the games now!"
$command = "$c $a $b $d!";
Note that if your string contains quotes, carriage returns or
backslashes, it's necessary to escape these special characters with a backslash.
// will cause an error due to mismatched quotes
$film = 'America's Sweethearts';
// will be fine
$film = 'America\'s Sweethearts';
// will generate an error
$story = "...and so he said, "backslash me, knave!"";
// will be fine
$story = "...and so he said, \"backslash me, knave!\"";
The print() function is used to output a string or string
PHP also offers the echo() construct, which does the same
// string variable
$author = "Shakespeare";
// combine the two
echo "Despite what critics may say, $author's influence can be felt even
Since displaying variable values is one of the most
fundamental things you can do, PHP also offers a shortcut syntax (similar to that offered by JSP) to simplify this task. The following two statements are equivalent: