PHP Strings

0
2390

A String is sequence of character like “Hello Microtech!!”.


 

PHP String Functions

In this chapter we will look at some commonly used functions to manipulate strings.


 

Get The Length of a String

The PHP strlen() function returns length of a string (number of character)


 

Count Number of word in a string

The PHP str_word_count() function counts number of words in a string.


 

Reverse a String

The strrev() function reverse a string.


Search for Specific text within a string

The PHP strpos() function search for specific text within a string.


Replace Text Within a String

The PHP str_replace() function replaces some characters with some other characters in a string.


 

[sam id=”4″ codes=”true”]

 

[nextpage title=”Program” ]

[message_box color=”yellow”]

<html>
<body>

<?php
echo strlen(“Hello Microtech!”);
echo “<br>”;
echo strrev(“Hello Microtech!”);
echo “<br>”;
echo str_word_count(“Hello Microtech!”);
echo “<br>”;
echo strpos(“Hello Microtech!”, “Microtech”);
echo “<br>”;
echo str_replace(“Microtech”, “Engineers”, “Hello Microtech!”);
?>

</body>
</html>

[/message_box]
[/nextpage]

[nextpage title=”Output” ]

[message_box color=”yellow”]

16
!hcetorciM olleH
2
6
Hello Engineers!

[/message_box]
[/nextpage]