PHP Strings
if we see the real word string then it’s the bunch of threads. same in the programming world if we have stream of characters it is called string
Concatenation
in our daily life programing tasks we need many time to join different string to show the proper output. in PHP we concatenate the two or more strings with dot(.)
<!doctype html>
<html>
<head>
<title>
PHP String Concatenation
</title>
</head>
<body>
<?php
$name="Qasim";
echo "Welcome ".$name; //output shows "Welcome Qasim"
?>
</body>
</html>
String Type
In php we are allowed to wrap our string with double quote(“text”) or with single quote. but both have difference if you want exact string content then enclosed your string into single quote. else if you are suing a variable in your string then use Double quote for proper execution of variable.
<!doctype html>
<html>
<head>
<title>
PHP String Types
</title>
</head>
<body>
<?php
$name="Qasim";
echo 'Variable name is $name'; // it shows Variable name is $name
echo "Welcome Mr. $name"; //it shows Welcome Mr. Qasim
?>
</body>
</html>
Escape Character
Some time we require single quote (‘) or double Quote (“) in our content. but these two characters are used by php so we are required to use escape sequence to include such a special characters which are not usable in straight way. Escape characters starts with “\”
<!doctype html>
<html>
<head>
<title>
PHP Escape Character
</title>
</head>
<body>
<?php
//Usage of single Quote (')
echo 'My all class teacher\'s are very nice';
echo "Welcome Mr.\t$name"; //Tab Escape Sequence
?>
</body>
</html>