STRING REPLACE
(I)
$bhavik = str_replace("college", "school", "I love my college");
Print $bhavik;
This is output: I love my school
(II)
$numbers = array("1", "2", "3");
$words = array("one", "two", "three");
$phrase = "I have only 1 girlfriend and 3 friends";
$bhavik = str_replace($numbers, $words, $phrase);
Print $bhavik;
This is output: I have only one girlfriend and three friends
...........................................................
STRING POSITION
echo strpos("Hello BHAVIK!","BHAVIK");
output:- 6
.........................................................................................
STRING LENGTH
echo strlen("Hello BHAVIK");
output:-12
............................................................
The strtolower() function converts a string to lowercase.
echo strtolower("Hello BHAVIK.");
............................................................
The substr() function returns a part of a string.
substr(string,start,length)
echo substr("Hello BHAVIK!",6);
..............................................................
STRING WORD COUNT
If you want to find out the number of words in a string, you can use str_word_count():
$bhavik = 'bhavik, dutt!';
echo str_word_count( $bhavik );
Output:- "2"
................................................................
Recent Comments