无需言 做自己 业 ,精于勤 荒于嬉.
- 字符串 函数 strcoll 基于区域设置的字符串比较
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
strcoll
(PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8)
strcoll — 基于区域设置的字符串比较
说明
strcoll(string$str1, string$str2): int注意该比较区分大小写。和 strcmp() 不同,该函数不是二进制安全的。
strcoll() 使用当前区域设置进行比较。如果当前区域为 C 或 POSIX,该函数等同于 strcmp()。
参数
-
str1 -
第一个字符串。
-
str2 -
第二个字符串。
返回值
如果
str1小于str2返回 < 0; 如果str1大于str2返回 > 0;如果两者相等,返回 0。更新日志
版本 说明 4.2.3 函数在 Win32 平台可用。 参见
- preg_match() - 执行匹配正则表达式
- strcmp() - 二进制安全字符串比较
- strcasecmp() - 二进制安全比较字符串(不区分大小写)
- substr() - 返回字符串的子串
- stristr() - strstr 函数的忽略大小写版本
- strncasecmp() - 二进制安全比较字符串开头的若干个字符(不区分大小写)
- strncmp() - 二进制安全比较字符串开头的若干个字符
- strstr() - 查找字符串的首次出现
- setlocale() - 设置地区信息
-
- 字符串 函数 strcspn 获取不匹配遮罩的起始子字符串的长度
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $a = strcspn('abcd', 'apple'); $b = strcspn('abcd', 'banana'); $c = strcspn('hello', 'l'); $d = strcspn('hello', 'world'); var_dump($a); var_dump($b); var_dump($c); var_dump($d); ?>
- 字符串 函数 stripos 查找字符串首次出现的位置(不区分大小写)
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $findme = 'a'; $mystring1 = 'xyz'; $mystring2 = 'ABC'; $pos1 = stripos($mystring1, $findme); $pos2 = stripos($mystring2, $findme); // 'a' 当然不在 'xyz' 中if ($pos1 === false) { echo "The string '$findme' was not found in the string '$mystring1'"; } // 注意这里使用的是 ===。简单的 == 不能像我们期望的那样工作,// 因为 'a' 的位置是 0(第一个字符)。if ($pos2 !== false) { echo "We found '$findme' in '$mystring2' at position $pos2"; } ?>
- 字符串 函数 strip_tags 从字符串中去除 HTML 和 PHP 标记
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php strip_tags($input, '<br>'); ?>
示例2
<?php $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'; echo strip_tags($text); echo "\n"; // 允许 <p> 和 <a>echo strip_tags($text, '<p><a>'); ?>
- 字符串 函数 stristr strstr() 函数的忽略大小写版本
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $email = 'USER@EXAMPLE.com'; echo stristr($email, 'e'); // 输出 ER@EXAMPLE.com echo stristr($email, 'e', true); // 自 PHP 5.3.0 起,输出 US?>
示例2
<?php $string = 'Hello World!'; if(stristr($string, 'earth') === FALSE) { echo '"earth" not found in string'; } // 输出: "earth" not found in string?>示例3
<?php $string = 'APPLE'; echo stristr($string, 97); // 97 = 小写字母 a// 输出: APPLE?>
- 字符串 函数 stripcslashes 反引用一个使用 addcslashes() 转义的字符串
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
说明
stripcslashes(string$str): string返回反转义后的字符串。可识别类似 C 语言的
\n,\r,... 八进制以及十六进制的描述。参数
-
str -
需要反转义的字符串。
返回值
返回反转义后的字符串。
-
- 字符串 函数 strnatcmp 使用自然排序算法比较字符串
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $arr1 = $arr2 = array("img12.png", "img10.png", "img2.png", "img1.png"); echo "Standard string comparison\n"; usort($arr1, "strcmp"); print_r($arr1); echo "\nNatural order string comparison\n"; usort($arr2, "strnatcmp"); print_r($arr2); ?>
- 字符串 函数 strnatcasecmp 使用“自然顺序”算法比较字符串(不区分大小写)
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
strnatcasecmp
(PHP 4, PHP 5, PHP 7, PHP 8)
strnatcasecmp — 使用“自然顺序”算法比较字符串(不区分大小写)
说明
strnatcasecmp(string$str1, string$str2): int该函数实现了以人类习惯对数字型字符串进行排序的比较算法。除了不区分大小写,该函数的行为与 strnatcmp() 类似。更多信息,参见:Martin Pool 的» 自然顺序的字符串比较页面。
参数
-
str1 -
第一个字符串。
-
str2 -
第二个字符串。
返回值
与其他字符串比较函数类似,如果
str1小于str2返回 < 0; 如果str1大于str2返回 > 0;如果两者相等,返回 0。参见
- preg_match() - 执行匹配正则表达式
- strcmp() - 二进制安全字符串比较
- strcasecmp() - 二进制安全比较字符串(不区分大小写)
- substr() - 返回字符串的子串
- stristr() - strstr 函数的忽略大小写版本
- strncasecmp() - 二进制安全比较字符串开头的若干个字符(不区分大小写)
- strncmp() - 二进制安全比较字符串开头的若干个字符
- strstr() - 查找字符串的首次出现
- setlocale() - 设置地区信息
-
- 字符串 函数 strlen 获取字符串长度
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = 'abcdef'; echo strlen($str); // 6$str = ' ab cd '; echo strlen($str); // 7?>
- 字符串 函数 strncasecmp 二进制安全比较字符串开头的若干个字符(不区分大小写)
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
strncasecmp
(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
strncasecmp — 二进制安全比较字符串开头的若干个字符(不区分大小写)
说明
strncasecmp(string$str1, string$str2, int$len): int该函数与 strcasecmp() 类似,不同之处在于你可以指定两个字符串比较时使用的长度(即最大比较长度)。
参数
-
str1 -
第一个字符串。
-
str2 -
第二个字符串。
-
len -
最大比较长度。
返回值
如果
str1小于str2返回 < 0; 如果str1大于str2返回 > 0;如果两者相等,返回 0。参见
- strncmp() - 二进制安全比较字符串开头的若干个字符
- preg_match() - 执行匹配正则表达式
- substr_compare() - 二进制安全比较字符串(从偏移位置比较指定长度)
- strcasecmp() - 二进制安全比较字符串(不区分大小写)
- stristr() - strstr 函数的忽略大小写版本
- substr() - 返回字符串的子串
-
- 字符串 函数 strncmp 二进制安全比较字符串开头的若干个字符
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
strncmp
(PHP 4, PHP 5, PHP 7, PHP 8)
strncmp — 二进制安全比较字符串开头的若干个字符
说明
strncmp(string$str1, string$str2, int$len): int该函数与 strcmp() 类似,不同之处在于你可以指定两个字符串比较时使用的长度(即最大比较长度)。
注意该比较区分大小写。
参数
-
str1 -
第一个字符串。
-
str2 -
第二个字符串。
-
len -
最大比较长度。
返回值
如果
str1小于str2返回 < 0; 如果str1大于str2返回 > 0;如果两者相等,返回 0。参见
- strncasecmp() - 二进制安全比较字符串开头的若干个字符(不区分大小写)
- preg_match() - 执行匹配正则表达式
- substr_compare() - 二进制安全比较字符串(从偏移位置比较指定长度)
- strcmp() - 二进制安全字符串比较
- strstr() - 查找字符串的首次出现
- substr() - 返回字符串的子串
-
- 字符串 函数 strrchr 查找指定字符在字符串中的最后一次出现
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php // 获取 $PATH 中不含磁盘符号的目录$dir = substr(strrchr($PATH, ":"), 1); // 获取最后一行内容$text = "Line 1\nLine 2\nLine 3"; $last = substr(strrchr($text, 10), 1 ); ?>
- 字符串 函数 similar_text 计算两个字符串的相似度
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
similar_text
(PHP 4, PHP 5, PHP 7, PHP 8)
similar_text — 计算两个字符串的相似度
说明
similar_text(string$first, string$second, float&$percent= ?): int两个字符串的相似程度计算依据 Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1) 的描述进行。注意该实现没有使用 Oliver 虚拟码中的堆栈,但是却进行了递归调用,这个做法可能会导致整个过程变慢或变快。也请注意,该算法的复杂度是 O(N**3),N 是最长字符串的长度。
参数
-
first -
第一个字符串。
-
second -
第二个字符串。
-
percent -
通过引用方式传递第三个参数,similar_text() 将计算相似程度百分数。
返回值
返回在两个字符串中匹配字符的数目。
-
- 字符串 函数 sprintf 返回格式化字符串
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php $num = 5; $location = 'tree'; $format = 'There are %d monkeys in the %s'; echo sprintf($format, $num, $location); ?>
示例2
<?php $format = 'The %s contains %d monkeys'; echo sprintf($format, $num, $location); ?>
示例3
<?php $format = 'The %2$s contains %1$d monkeys'; echo sprintf($format, $num, $location); ?>
示例4
<?php $format = 'The %2$s contains %1$d monkeys. That\'s a nice %2$s full of %1$d monkeys.'; echo sprintf($format, $num, $location); ?>
示例5
<?php echo sprintf("%'.9d\n", 123); echo sprintf("%'.09d\n", 123); ?>示例6
<?php $format = 'The %2$s contains %1$04d monkeys'; echo sprintf($format, $num, $location); ?>
示例7
<?php $isodate = sprintf("%04d-%02d-%02d", $year, $month, $day); ?>示例8
<?php $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; echo $money; echo "\n"; $formatted = sprintf("%01.2f", $money); echo $formatted; ?>示例9
<?php $number = 362525200; echo sprintf("%.3e", $number); ?>
- 字符串 函数 parse_str 将字符串解析成多个变量
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = "first=value&arr[]=foo+bar&arr[]=baz"; // 推荐用法parse_str($str, $output); echo $output['first']; // valueecho $output['arr'][0]; // foo barecho $output['arr'][1]; // baz// 不建议这么用parse_str($str); echo $first; // valueecho $arr[0]; // foo barecho $arr[1]; // baz?>
示例2
<?php parse_str("My Value=Something"); echo $My_Value; // Somethingparse_str("My Value=Something", $output); echo $output['My_Value']; // Something?>
- 字符串 函数 soundex Calculate the soundex key of a string
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php soundex("Euler") == soundex("Ellery"); // E460soundex("Gauss") == soundex("Ghosh"); // G200soundex("Hilbert") == soundex("Heilbronn"); // H416soundex("Knuth") == soundex("Kant"); // K530soundex("Lloyd") == soundex("Ladd"); // L300soundex("Lukasiewicz") == soundex("Lissajous"); // L222?>
- 字符串 函数 sscanf 根据指定格式解析输入的字符
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php // getting the serial numberlist($serial) = sscanf("SN/2350001", "SN/%d"); // and the date of manufacturing$mandate = "January 01 2000"; list($month, $day, $year) = sscanf($mandate, "%s %d %d"); echo "Item $serial was manufactured on: $year-" . substr($month, 0, 3) . "-$day\n"; ?>示例2
<?php // get author info and generate DocBook entry$auth = "24\tLewis Carroll"; $n = sscanf($auth, "%d\t%s %s", $id, $first, $last); echo "<author id='$id'> <firstname>$first</firstname> <surname>$last</surname></author>\n"; ?>
- 字符串 函数 str_ends_with Checks if a string ends with a given substring
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php if (str_ends_with('abc', '')) { echo "All strings end with the empty string"; } ?>示例2
<?php $string = 'The lazy fox jumped over the fence'; if (str_ends_with($string, 'fence')) { echo "The string ends with 'fence'\n"; } if (str_ends_with($string, 'Fence')) { echo 'The string ends with "fence"'; } else { echo '"fence" was not found because the case does not match'; } ?>
- 字符串 函数 str_getcsv 解析 CSV 字符串为一个数组
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
str_getcsv
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
str_getcsv — 解析 CSV 字符串为一个数组
说明
str_getcsv(
string$input,
string$delimiter= ",",
string$enclosure= '"',
string$escape= "\\"
): array以 CSV 字段格式解析字符串输入,并返回包含读取字段的数组。
参数
-
input -
待解析的字符串。
-
delimiter -
设定字段界定符(仅单个字符)。
-
enclosure -
设定字段包裹字符(仅单个字符)。
-
escape -
设置转义字符(仅单个字符)。默认为反斜线(
\)。
返回值
返回一个包含读取到的字段的索引数组。
-
- 字符串 函数 sha1 计算字符串的 sha1 散列值
-
发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = 'apple'; if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') { echo "Would you like a green or red apple?"; } ?>
- 前端开发(1)
- 数据库(0)
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)
- JAVA(0)
- Android(0)
- Linux(0)
- AI大模型(9)
- 其他(0)
宁公网安备 64010402001209号