PHP string common functions

巴扎黑
Release: 2016-11-23 10:41:27
Original
1167 people have browsed it

strlen(string) returns the length of the string.

implode(separator,array)

function combines array elements into a string.

separator optional. Specifies what is placed between array elements. Default is "" (empty string).

array required. Arrays to be combined into strings.

explode(separator,string,limit)

Split the string into an array.

separator required. Delimiter

string required. The string to split.

limit optional. Specifies the maximum number of array elements returned.

strpos(string,find,start)

Returns the position of the first occurrence of a string in another string. If the string is not found, it returns false.

string required. Specifies the string to be searched for.

find required. Specifies the characters to search for.

start optional. Specifies the location from which to start the search.

Note: This function is case sensitive. For case-insensitive searches, use the stripos() function.

stripos(string,find,start)

Returns the position of the first occurrence of a string in another string. If the string is not found, it returns false.

string required. Specifies the string to be searched for.

find required. Specifies the characters to search for.

start optional. Specifies the location from which to start the search.

Note: This function is not case sensitive. For case-sensitive searches, use the strpos() function.

Php code

$findme = 'a';

$mystring1 = 'xyz';

$mystring2 = 'ABC';

$pos1 = stripos ($mystring1, $ findme);

$pos2 = stripos($mystring2, $findme);

// Note, 'a' is certainly not in 'xyz'

if ($pos1 === false) {

echo "The string '$findme' was not found in the string '$mystring1'";

}

// Note our use of ===. Simply == would not work as expected

// because the position of 'a' is the 0th (first) character.

if ($pos2 !== false) {

echo "We found '$findme' in '$mystring2' at position $pos2";

}

?>

rtrim(string,charlist)

Remove whitespace characters or other predefined characters starting from the end of the string.

string required. Specifies the string to be converted.

charlist optional. Specifies which characters are removed from the string. If this parameter is not set, all the following characters will be deleted:

•"

Convert the first character in the string to uppercase.

strtoupper(string)

Convert a string to uppercase.

strtolower(string)

Convert the string to lowercase.

strrev(string)

Reverse a string.


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!