PHP STRINGS
In PHP a string variable is used to store and manipulate a piece of text, string variables are used for a value that contains character strings.
Below example explains the PHP script assigns the string "Web designing company" to a string variable called $txt;
<?php
$txt="Web designing company";
echo $txt;
? >
OUTPUT:
Web designing company
Reverse a String:
The function strrev () is used to reverse the string what we type.
Code:
<!DOCTYPE html>
<html>
<body>
<?php
echo strrev("web designing company!");
?>
</body>
</html>
OUTPUT:
!ynapmoc giningised bew
Counting the words in a string:
The PHP str_word_count is used to count the number of words present in the string.
Code:
<!DOCTYPE html><html>
<body>
<?php
echo str_word_count("web designing company!");
?>
</body>
</html>
OUTPUT:
3
Counting the number of letters in a string:
The strlen() functions used to measure the number of the letters and gaps and the special characters.
Code:
<!DOCTYPE html>
<html>
<body>
<?php
echo strlen("web designing company!");
?>
</body>
</html>
23
In this, it will include the gap between words as well as the exclamatory symbol also.
No comments:
Post a Comment