Urdu Urdu English English

PHP String Functions

PHP String Functions:

As we Learn in the earlier lesson string is the sequence of alphabets/characters. Here we touch some PHP strings functions which are most usage in PHP language.

PHP Strlen() Function:

“Knowledge idea” is like a String. So we use length string function which task to count the alphabets of strings and display output on screen.Let’s take following example.

$x="Knowledge idea";
echo strlen($x); // Answer is 14

In above case first we assign a string to a variable $x then print the string value in strlen() function. Keep remember in mind space will consider/count then answer will be display with string characters include spaces.

PHP Strpos() Function:

PHP Strpos() is used to find a special/specific alphabet/character in the given string. If function got it then function return the first match position of the string. In the other condition not found function will return False.Let’s take the following example.

$x="knowledge idea";
echo strpos($x,"idea"); // Answer is 10

 According to your perceptions answer is 11. But you compiler shows 10. The reason is that string count start from 0 not 1.

List of PHP String function more…

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments