Share on Google+Share on Google+

PHP Concatenation Operator

Advertisement
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.

Advertisements

Posted on: July 10, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.