String functions in php

String functions in php

When we are working on string value and doing some innovative thing using string functions we need to define it first so there are serval type of string functions are available in php which is describe in below list. basically string function is used to show string value differently, Do changes of string value, check some values of string and many more reasons. In below list we can see what are the string functions available in php.

Different types of string function in php

  1. chr()
  2. ord()
  3. strtolower()
  4. strtoupper()
  5. strlen()
  6. ltrim()
  7. rtrim()
  8. substr()
  9. strcmp()
  10. strpos()
  11. strrpos()
  12. strstr()
  13. stristr()
  14. str_replace()
  15. strrev()
  16. echo()
  17. print()

This all above listed is used to define a string value for a specific use. Now let’s see use of the sting functions in php

1.    Chr()

The chr() function returns a character from the specified ASCII value.
Syntax: chr(ascii);

2.     ord()

The ord() function returns the ASCII value of the first character of a string.
Syntax: ord(string);

3.    strtolower()

The strtolower() function converts a string to lowercase.
Syntax: strtolower(string);

4.    strtoupper()

The strtoupper() function converts a string to uppercase.
Syntax: strtoupper(string);

5.    strlen()

The strlen() function returns the length of a string.
Syntax: strlen(string);

6.    rtrim()

The rtrim() function will remove whitespaces or other predefined character from the right side of a string.
Syntax: rtrim(string,charlist);

7.    substr()

The substr() function returns a part of a string.
Syntax: substr(string,start,length);

8.    The strcmp() function compares two strings.

This function returns:

  • 0 - if the two strings are equal
  • <0 - if string1 is less than string2
  • >0 - if string1 is greater than string2

Syntax: strcmp(string1,string2);

9.    strcasecmp()

The strcasecmp() function compares two strings.

This function returns:

  • 0 - if the two strings are equal
  • <0 - if string1 is less than string2
  • >0 - if string1 is greater than string2

Syntax: strcasecmp(string1,string2);

10.    strpos()

The strpos() function returns the position of the first occurrence of a string inside another string. If the string is not found, this function returns FALSE.
Syntax: strpos(string,find,start);

11.    strrpos()

The strrpos() function finds the position of the last occurrence of a string inside another string. This function returns the position on success, otherwise it returns FALSE.

Syntax: strrpos(string,find,start);

12.    strstr()

The strstr() function searches for the first occurrence of a string inside another string. This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.
Syntax: strstr(string,search)

13.    stristr()

The stristr() function searches for the first occurrence of a string inside another string.This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.
Syntax: stristr(string,search);

14.    str_replace()

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

This function works by the following rules:

  • If the string to be searched is an array, it returns an array.
  • If the string to be searched is an array, find and replace is performed with every array element.
  • If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace.
  • If find is an array and replace is a string, the replace string will be used for every find Value.

Syntax:  str_replace(find,replace,string,count);

15.    strrev()

The strrev() function reverses a string.
Syntax: strrev(string);

16.    echo()

The echo() function outputs one or more strings.
Syntax: echo(strings);
Tip:  The echo() function is slightly faster than print().

17.    print()

The print() function outputs one or more strings.
Syntax:  print(strings);

So, this is all about string functions of php. If you want to know more about it please wait for next article. Hope you like this article don’t forget to share with your friends. See you soon.

Also Read:

Bootstrap 5 : what’s new in bootstrap 5 new releases Part-1

Post Comments(0)

Leave a reply