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.
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.
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.
String functions –strtr()
strtr() used to translate certain characters of a string into other characters.
- Single character version
- Multiple-character version
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.
0
6
6
String functions –stripos() , strrpos()
stripos() is case-insensitive version of strpos().
stripos() is case-insensitive version of strpos().
Output- 0
Strpos() does the same as strpos(), but in the revers order.
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:
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().
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.
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().
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:
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
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 –substr()
The very flexible and powerful substr() function allows you to extract a substring from a larger string.
1
2
3
4
5
|
echo substr ($x, 0, 3);// outputs 123
echo substr ($x, 1, 1);// outputs 2
echo substr ($x, -2); //outputs 67
echo substr ($x, 1); //outputs 234567
echo substr ($x, -2, 1); //outputs 6
|
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.
Number formatting is typically used when you wish to output a number and separate its digits into thousands and decimal points.
Tidak ada komentar:
Posting Komentar