Some common functions for string processing in PHP

silencement
Release: 2023-04-08 10:56:02
forward
3317 people have browsed it

Some common functions for string processing in PHP

In our development of PHP, string processing is one of our most commonly used operations. Mastering some of the commonly used string processing functions of PHP will allow you to develop in PHP. , both in terms of technology and efficiency, it will be upgraded to a higher level.

The following are some common functions for PHP string processing

String output

echo():输出一个或多个字符串
print():输出一个字符串
printf():输出格式化字符串
Copy after login

String removal

trim():去除字符串 首尾 空白等特殊符号或指定字符序列
ltrim():去除字符串 首 空白等特殊符号或指定字符序列
rtrim():去除字符串 尾 空白等特殊符号或指定字符序列
chop():同 rtrim()
Copy after login

String concatenation

implode():使用字符将数组的内容组合成一个字符串
join():同 implode()
Copy after login

String splitting

explode():使用一个字符串分割另一个字符串,将字符串分割到数组中
Copy after login

String acquisition

substr():从字符串中获取其中的一部分
strstr():查找字符串在另一个字符串中第一次出现的位置,并返回从该位置到字符串结尾的所有字符
subchr():同 strstr()
strrchr():查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符
Copy after login

String replacement

substr_replace():把字符串的一部分替换为另一个字符串
str_replace():使用一个字符串替换字符串中的另一些字符
Copy after login

String calculation

strlen():取得字符串的长度
strpos():定位字符串第一次出现的位置
strrpos():定位字符串最后一次出现的位置
Copy after login

String XHTML formatted display

nl2br():将换行符 n 转换成 XHTML 换行符 
htmlspecialchars():把一些特殊字符转换为 HTML 实体
htmlspecialchars_decode():把一些 HTML 实体转换为特殊字符,htmlspecialchars() 的反函数
Copy after login

String Store (escape)

addslashes():对特殊字符加上转义字符。
stripslashes():addslashes() 的反函数。
Copy after login

The above is the detailed content of Some common functions for string processing in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:www.liqingbo.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