Home Tutorial Php Phpbeginners PHP Concatenation Operator

 
 

PHP Concatenation Operator
Posted on: July 10, 2009 at 12:00 AM
The only one string operator in PHP is concatenation operator (.) that is used for putting two string values together; e.g.

The only one string operator in PHP is concatenation operator (.) that is used for putting two string values together; e.g.
<?php
$txt1=“Hello Buddy!";
$txt2=“How are you?”;
echo $txt1.” “. $txt2;
?>

The output of the code above will be:

Hello Budddy! How are you?

If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string (a space character), to separate the two strings.

3.4.3. The strlen() function

The strlen() function is used for returning the length of a string, e.g.

<?php
echo strlen(“Roseindia Technologies”);
?>

The output of the code above will be:
22

It also includes the space and special character in counting the length of string. Strlen() function is usually used in loops or other functions, when it is important to know when the string ends (i.e. in a loop, we would want to stop the loop after the last character in the string).

3.4.4. The strpos() function

The strpos() function is used to search for character within a string. If it founds the character, it will return the position and if fail, it shows false; e.g.

Counting the India string in Rose India string:

<?php
echo strpos(“Rose India!”, “India”);
?>

The output of the code above will be:
5

Because, it counts the first position of string is 0 not 1.

Related Tags for PHP Concatenation Operator:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.