Home>Article>Backend Development> Some common functions for string processing in PHP

Some common functions for string processing in PHP

silencement
silencement forward
2020-01-27 21:32:00 3145browse

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():输出格式化字符串

String removal

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

String concatenation

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

String splitting

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

String acquisition

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

String replacement

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

String calculation

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

String XHTML formatted display

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

String Store (escape)

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

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!

Statement:
This article is reproduced at:www.liqingbo.cn. If there is any infringement, please contact admin@php.cn delete