String functions

String functions –strcmp(), strcasecmp()

strcmp(), strcasecmp() both returns zero if the two strings passed to the function are equal. These are identical, with the exception that the former is case-sensitive, while the latter is not.

String functions –strcasencmp()
strcasencmp() allows you to only test a given number of characters inside two strings.

String functions –strlen()
strlen() is used to determine the length of a string.

Output – 28
String functions –strtr()
strtr() used to translate certain characters of a string into other characters.

  • Single character version
    Output – 1bc
  • Multiple-character version
    Output- onetwo3

String functions –strpos()

  •  strpos() allows you to find the position of a substring inside a string. It returns either the numeric position of the substring’s first occurrence within the string, or false if a match could not be found.
  • You can also specify an optional third parameter to strpos() to indicate that you want the search to start from a specific position within the haystack.
    Output – 


String functions –stripos() , strrpos()
 stripos() is case-insensitive version of strpos().

Output- 0
Strpos() does the same as strpos(), but in the revers order.

Output- 3
String functions –strstr()
The strstr() function works similarly to strpos() in that it searches the main string for a substring. The only real difference is that this function returns the portion of the main string that starts with the sub string instead of the latter’s position:

Output- 3456
String functions –stristr()
stristr() is case-insensitive version of strstr().

Output- My World
String functions –str_replace(), str_ireplace()
str_replace() used to replace portions of a string with a different substring.

Output- Hello Reader
Str_ireplace() is the case insensitive version of str_replace().

Output- Hello Reader
Optionally, you can specify a third parameter, that the function fills, upon return, with the number of substitutions made:

Output- 3
If you need to search and replace more than one needle at a time, you can pass the first two arguments to str_replace() in the form of arrays

Output – Hello Reader

Output – Bye Bye
String functions –substr()
The very flexible and powerful substr() function allows you to extract a substring from a larger string.

String functions –number_format()
Number formatting is typically used when you wish to output a number and separate its digits into thousands and decimal points.
imagesOutput- 100 000,698

Anuj Kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Recommended Tutorials for you

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *