在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.strstr(string $str,mixed $needle[, bool $before_needle = FALSE ]) 参数 $str 输入的字符串 ,$needle 查找的字符串,$before_needle 布尔值 $str = 'abc@yui' echo strstr($str,'@'); //@yui //返回字符串$str从@(needle)到结尾部分 echo PHP_EOL; echo strstr($str,'@',true); //abc //返回字符串$str中的@之前的部分 2.string strrev(string $string) echo strrev('xp'); //px 3.strlen(string $string); echo strlen('汉语');//6 4.mb_strlen(string $str [, string $encoding = mb_internal_encoding() ]) echo mb_strlen('你好','utf-8');//utf-8编码格式的页面,使用utf-8编码输出2, echo mb_strlen('你好','gbk'); //gbk编码格式的页面,使用gbk编码输出2 5.strtolower() 返回转换后的小写字符串。 $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 6.strtoupper() echo strtoupper('i love you'); // I LOVE YOU 7.ucwords(string $string)— 将字符串中每个单词的首字母转换为大写 echo ucwords('hello world'); // Hello World $foo = 'hello|world you!';
8.string ucfirst ( string $str ) echo $foo = ucfirst($foo); // Hello world!
9.str_replace(mixed $search,mixed $replace,string $str) $str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; // 首先替换 \r\n 字符,因此它们不会被两次转换 echo $newstr = str_replace($order, $replace, $str); //Line 1<br />Line 2<br />Line 3<br />Line 4<br /> // 赋值: <body text='black'> echo $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); //<body text='black'> // 赋值: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); echo $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); // Hll Wrld f PHP // 赋值: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); echo $newphrase = str_replace($healthy, $yummy, $phrase); //You should eat pizza, beer, and ice cream every day // 赋值: 2 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; //3
10. str_ireplace(mixed $search,mixed $replace, $str); 11.将特殊字符转换为 HTML 实体 $new = htmlspecialchars("<a href='test'>Test</a>"); echo $new; // <a href='test'>Test</a> 12. echo PHP_EOL; echo htmlspecialchars_decode($new); //<a href='test'>Test</a> 13.trim — 去除字符串首尾处的空白字符(或者其他字符) $text = "\t\tThese are a few words :) ... "; $binary = "\x09Example string\x0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); /*string(32) " These are a few words :) ... " string(16) " Example string " string(11) "Hello World"*/ print "\n";
14. 参数 $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // 例子1 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作, // 因为 '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 忽视位置偏移量之前的字符进行查找 $newstring = 'abcdef abcdef'; $pos = strpos($newstring, 'a', 1); // $pos = 7, 不是 0 15. stripos($str,'a’)*/;//同上 但是不区分大小写 $foo = "0123456789a123456789b123456789c"; var_dump(strrpos($foo, '7', -4)); // 从尾部第 5 个位置开始向左查找知道字符后输出此字符从左向右查找时所占的位置 // 结果: int(17) var_dump(strrpos($foo, '7', 20)); // 从第 20 个位置开始查找 // 结果: int(27) var_dump(strrpos($foo, '7', 28)); // 结果: bool(false) /*16. 17 $rest = substr("abcdef", -1); // 返回 "f" $rest = substr("abcdef", -2); // 返回 "ef" $rest = substr("abcdef", -3, 1); // 返回 "d" length $rest = substr("abcdef", 0, -1); // 返回 "abcde" $rest = substr("abcdef", 2, -1); // 返回 "cde" $rest = substr("abcdef", 4, -4); // 返回 "" $rest = substr("abcdef", -3, -1); // 返回 "de" 18 echo strrchr("Hello world! What a beautiful day!",What); //搜索 "What" 在字符串中的位置,并返回从该位置到字符串结尾的所有字符: echo strrchr("Hello world!",101); //以 "o" 的 ASCII 值搜索 "o" 在字符串中的位置,并返回从该位置到字符串结尾的所有字符: 19str_shuffle()随机地打乱字符串中的所有字符 echo str_shuffle('hellow'); //lehowl
|
2022-08-15
2022-08-17
2022-11-06
2022-08-17
2022-07-18
请发表评论