PHP TUTORIAL
String Variable in PHP
In the previous chapter we briefly learned learned about string variable. Let us learn more about strings.
Combining two strings
A . operator can be used to combine two strings. As an example.
<?php $text1 = "My Name is John ."; $text2 = "And I live in MA, USA"; $text3 = $text1.$text2; echo $text3; ?> |
My Name is John .And I live in MA, USA
This is also called String Concatenation. We can use a combinatin of variables and constants to concatenate two or more strings. Take a look at the following example. It gives output something like
My Name is John .And I live in MA, USA
strlen() function - Finding String length
To find the length of string you can use the strlen function. Take a look at he folloing code.
<?php $text1 = "It is easy to understand PHP using referencedesigner.com Tutorial "; $length = strlen($text1); echo " Length of string is :".$length; ?> |
This gives the code like this
Length of string is :67
PHP Supports a huge number of strings related functions. We will come back to it again later. Before that we will learn about if then construct.