A String is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes.
Ex: "Hello", 'php' etc..
<?php $str = "hai PHP"; echo $str; ?>
In the above example, we store the string value " hai PHP " in a variable name $str and use echo to output its value.
PHP Strings in Single and Double QuotesStrings in Double Quotes:
As we saw in our examples, strings are wrapped in double quotes. Using double quotes is the primary method. Double quotes allow us to escape specials characters in our string. For example, you can use a single quotes with in double quotes.
<?php $str = "It's a nice day today." echo $str; ?>
Strings in Single Quotes:
Strings are wrapped in single quotes. Using single quotes is the secondary method.
<?php $str = 'This is a PHP string examples in single quotes'; echo $str; ?>
Concatenating Strings in PHP:
Sometimes while working with strings in our code, we need to join two strings. In PHP, you can use '.' to concatenate two or more strings together to form a single string.Example1:
<?php $ex1 = "hai PHP."; $ex2 = "PHP is usefull."; echo $ex1." ".$ex2; ?>
<?php $str1 = "I Love PHP."; $str2 = $str1." PHP is fun to learn."; echo $str2; ?>