无需言 做自己 业 ,精于勤 荒于嬉.
- 字符串 函数 stripslashes 反引用一个引用字符串
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = "Is your name O\'reilly?"; // 输出: Is your name O'reilly?echo stripslashes($str); ?>
示例2
<?php function stripslashes_deep($value){ $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } // 范例$array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")); $array = stripslashes_deep($array); // 输出print_r($array); ?>
- 字符串 函数 strrev 反转字符串
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php echo strrev("Hello world!"); // 输出 "!dlrow olleH"?>
- 字符串 函数 strripos 计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $haystack = 'ababcd'; $needle = 'aB'; $pos = strripos($haystack, $needle); if ($pos === false) { echo "Sorry, we did not find ($needle) in ($haystack)"; } else { echo "Congratulations!\n"; echo "We found the last ($needle) in ($haystack) at position ($pos)"; } ?>
- 字符串 函数 strrpos 计算指定字符串在目标字符串中最后一次出现的位置
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $pos = strrpos($mystring, "b"); if ($pos === false) { // 注意: 三个等号 // 未发现...} ?>示例2
<?php $foo = "0123456789a123456789b123456789c"; var_dump(strrpos($foo, '7', -5)); // 从尾部第 5 个位置开始查找 // 结果: int(17)var_dump(strrpos($foo, '7', 20)); // 从第 20 个位置开始查找 // 结果: int(27)var_dump(strrpos($foo, '7', 28)); // 结果: bool(false)?>
- 字符串 函数 strstr 查找字符串的首次出现
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // 打印 @example.com$user = strstr($email, '@', true); // 从 PHP 5.3.0 起echo $user; // 打印 name?>
- 字符串 函数 strtok 标记分割字符串
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $string = "This is\tan example\nstring"; /* 使用制表符和换行符作为分界符 */ $tok = strtok($string, " \n\t"); while ($tok !== false) { echo "Word=$tok<br />"; $tok = strtok(" \n\t"); } ?>示例2
<?php $first_token = strtok('/something', '/'); $second_token = strtok('/'); var_dump($first_token, $second_token); ?>
- 字符串 函数 strtoupper 将字符串转化为大写
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = "Mary Had A Little Lamb and She LOVED It So"; $str = strtoupper($str); echo $str; // 打印 MARY HAD A LITTLE LAMB AND SHE LOVED IT SO?>
- 字符串 函数 strpos 查找字符串首次出现的位置
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作,// 因为 'a' 是第 0 位置上的(第一个)字符。if ($pos === false) { echo "The string '$findme' was not found in the string '$mystring'"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } ?>示例2
<?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // 使用 !== 操作符。使用 != 不能像我们期待的那样工作,// 因为 'a' 的位置是 0。语句 (0 != false) 的结果是 false。if ($pos !== false) { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } else { echo "The string '$findme' was not found in the string '$mystring'"; } ?>示例3
<?php // 忽视位置偏移量之前的字符进行查找$newstring = 'abcdef abcdef'; $pos = strpos($newstring, 'a', 1); // $pos = 7, 不是 0?>
- 字符串 函数 substr_count 计算字串出现的次数
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $text = 'This is a test'; echo strlen($text); // 14echo substr_count($text, 'is'); // 2// 字符串被简化为 's is a test',因此输出 1echo substr_count($text, 'is', 3); // 字符串被简化为 's i',所以输出 0echo substr_count($text, 'is', 3, 3); // 因为 5+10 > 14,所以生成警告echo substr_count($text, 'is', 5, 10); // 输出 1,因为该函数不计算重叠字符串$text2 = 'gcdgcdgcd'; echo substr_count($text2, 'gcdgcd'); ?>
- 字符串 函数 strspn 计算字符串中全部字符都存在于指定字符集合中的第一段子串的长度。
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $var = strspn("42 is the answer to the 128th question.", "1234567890"); ?>示例2
<?php echo strspn("foo", "o", 1, 2); // 打印: 2?>
- 字符串 函数 substr_replace 替换字符串的子串
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $var = 'ABCDEFGH:/MNRPQR/'; echo "Original: $var<hr />\n"; /* 这两个例子使用 “bob” 替换整个 $var。*/ echo substr_replace($var, 'bob', 0) . "<br />\n"; echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />\n"; /* 将 “bob” 插入到 $var 的开头处。*/ echo substr_replace($var, 'bob', 0, 0) . "<br />\n"; /* 下面两个例子使用 “bob” 替换 $var 中的 “MNRPQR”。*/ echo substr_replace($var, 'bob', 10, -1) . "<br />\n"; echo substr_replace($var, 'bob', -7, -1) . "<br />\n"; /* 从 $var 中删除 “MNRPQR”。*/ echo substr_replace($var, '', 10, -1) . "<br />\n"; ?>
示例2
<?php $input = array('A: XXX', 'B: XXX', 'C: XXX'); // A simple case: replace XXX in each string with YYY.echo implode('; ', substr_replace($input, 'YYY', 3, 3))."\n"; // A more complicated case where each replacement is different.$replace = array('AAA', 'BBB', 'CCC'); echo implode('; ', substr_replace($input, $replace, 3, 3))."\n"; // Replace a different number of characters each time.$length = array(1, 2, 3); echo implode('; ', substr_replace($input, $replace, 3, $length))."\n"; ?>
- 字符串 函数 substr_compare 二进制安全比较字符串(从偏移位置比较指定长度)
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php echo substr_compare("abcde", "bc", 1, 2); // 0echo substr_compare("abcde", "de", -2, 2); // 0echo substr_compare("abcde", "bcg", 1, 2); // 0echo substr_compare("abcde", "BC", 1, 2, true); // 0echo substr_compare("abcde", "bc", 1, 3); // 1echo substr_compare("abcde", "cd", 1, 2); // -1echo substr_compare("abcde", "abc", 5, 1); // warning?>
- 字符串 函数 strtolower 将字符串转化为小写
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = "Mary Had A Little Lamb and She LOVED It So"; $str = strtolower($str); echo $str; // 打印 mary had a little lamb and she loved it so?>
- 字符串 函数 strtr 转换指定字符
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $addr = strtr($addr, "äåö", "aao"); ?>
示例2
<?php $trans = array("hello" => "hi", "hi" => "hello"); echo strtr("hi all, I said hello", $trans); ?>示例3
<?php echo strtr("baab", "ab", "01"),"\n"; $trans = array("ab" => "01"); echo strtr("baab", $trans); ?>
- 字符串 函数 trim 去除字符串首尾处的空白字符(或者其他字符)
-
发表日期:2021-07-01 10:23:25 | 来源: | 分类:字符串 函数
-
示例1
<?php $text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "\n"; $trimmed = trim($text); var_dump($trimmed); $trimmed = trim($text, " \t."); var_dump($trimmed); $trimmed = trim($hello, "Hdle"); var_dump($trimmed); // 清除 $binary 首位的 ASCII 控制字符 // (包括 0-31) $clean = trim($binary, "\x00..\x1F"); var_dump($clean); ?>
示例2
<?php function trim_value(&$value) { $value = trim($value); } $fruit = array('apple','banana ', ' cranberry '); var_dump($fruit); array_walk($fruit, 'trim_value'); var_dump($fruit); ?>
- 字符串 函数 str_split 将字符串转换为数组
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $str = "Hello Friend"; $arr1 = str_split($str); $arr2 = str_split($str, 3); print_r($arr1); print_r($arr2); ?>
- 字符串 函数 strcasecmp 二进制安全比较字符串(不区分大小写)
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $var1 = "Hello"; $var2 = "hello"; if (strcasecmp($var1, $var2) == 0) { echo '$var1 is equal to $var2 in a case-insensitive string comparison'; } ?>
- 字符串 函数 str_starts_with Checks if a string starts with a given substring
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php if (str_starts_with('abc', '')) { echo "All strings start with the empty string"; } ?>示例2
<?php $string = 'The lazy fox jumped over the fence'; if (str_starts_with($string, 'The')) { echo "The string starts with 'The'\n"; } if (str_starts_with($string, 'the')) { echo 'The string starts with "the"'; } else { echo '"the" was not found because the case does not match'; } ?>
- 字符串 函数 strcmp 二进制安全字符串比较
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
-
示例1
<?php $var1 = "Hello"; $var2 = "hello"; if (strcmp($var1, $var2) !== 0) { echo '$var1 is not equal to $var2 in a case sensitive string comparison'; } ?>
- 字符串 函数 strchr 别名 strstr()
-
发表日期:2021-07-01 10:23:24 | 来源: | 分类:字符串 函数
- 前端开发(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号