Sunday, 9 June 2013

What are different string functions in php?


Example -
There are many string function available in php that help us find the length of the variable , concatenate 2 variables, reverse the string, remove spaces from string etc..

Code and Syntax

<?php
$str = “hello”
$st1 = ‘hello’

// Concatenation operator
$txt1="Hello!";
$txt2="What!";
echo $txt1 . " " . $txt2;
?>

// find the length of string
//The strlen() function returns the length of a string, in characters.

<?php
echo strlen("Hello!");      //this will print 6
?>

//strpos finds the position of the text in another string.
<?php
echo strpos("Hello sagar!","sagar");  // this will print 6
?>

Explanation

You can assign a string variable using single quote or double quote.



 For more php questions and answers, dumps,tutorials for beginners and experienced people visit http://www.top-php-interview-questions.blogspot.in  If you find any errors while executing this program, you can make your comments or mail me at reply2sagar@gmail.com



No comments:

Post a Comment