Home >Backend Development >PHP Tutorial >String processing functions

String processing functions

WBOY
WBOYOriginal
2016-07-29 08:57:20864browse

1. String output function

echo

print

is not as efficient as echo and is not recommended to use

die()

Exit and print string a, too You can directly die

printf

formatted string

sprintf

return the formatted string

2. Commonly used string formatting functions

ltrim ()

Remove the white space on the left side

rtrim

Remove the white space on the right side

trim

Remove the white space on both sides

str_pad

Padding a string with another string to the specified length

strtolower

Convert a string to lowercase

strtopper

Convert a string to uppercase

ucfirst

Convert the first letter of the string to uppercase

usword

Convert the first letter of each word in the string to uppercase

nl2br

Insert HTML newline mark before all new lines in the string

htmlentities

Entities converted to tags

htmlspecialchars

Convert tags to entities

...


3. String comparison function

strcmp(a,b)

is sorted by bytes. If a is less than
b
, a negative number is returned; if

a

is greater than b, a positive number is returned; if they are equal, 0 is returned.

strcasecmp()

Same as above, but not case sensitive

strnatcmp()

Sort by natural numbers

The above has introduced the string processing function, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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