Home  >  Article  >  Backend Development  >  Write a program in PHP to implement the following functions

Write a program in PHP to implement the following functions

不言
不言Original
2018-05-31 13:31:071740browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn