Home > Article > Backend Development > Write a program in PHP to implement the following functions
Write a program to implement the following functions:
a. How to determine whether a character exists in a string
echo strstr('abcdefgcd' , 'cd'); echo strpos('ab0defgcd' , 'cd');
Example:
b. How to determine a string How many times does a character appear in?
echo substr_count('abcdefgcd' , 'cd');
Example:
c. How to remove the last character of a string
echo substr('abcdefgcd' , 0 , -1);
Example:
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr; //echo 1,2,3,4,5,6
The above is the detailed content of Write a program in PHP to implement the following functions. For more information, please follow other related articles on the PHP Chinese website!