Another important point is string concatenation. Often times you’ll need to concatenate strings together, and the easiest way of doing it is with a dot. For instance:

<?php
echo "Hello" . "World\n";
?>

Or:

<?php
$x = 10;
$y = 20;
echo $x + $y . "\n";
?>

The above code first adds x with y, then converts the result into a string, and then concatenate it with the “\n” string, effectively printing out 30 with a newline after it.

PHP comes with a huge amount of built-in string functions. You can check all them on the official PHP manual. For instance, there are functions to find the length of a string, to search for specific characters inside it, and pretty much anything else you might need.

Advertisements