Blogger Information
Blog 37
fans 0
comment 0
visits 34701
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
字符串函数
手机用户1607314868
Original
597 people have browsed it
  1. ltrim 删除字符串开头的空白字符(或其他字符)
    ltrim(输入字符串,指定想要删除的字符) : string
    该函数返回一个删除了str最左边的空白字符的字符串
  1. $hello = "Hello World";
  2. $trimmed = ltrim($hello, "Hdle");
  3. var_dump($trimmed);

2.str_shuffle — 随机打乱一个字符串
str_shuffle(字符串) : string

  1. $str = 'abcdef';
  2. $shuffled = str_shuffle($str);
  3. echo $shuffled;

3.strlen — 获取字符串长度
strlen( string $string) : int

  1. $str = 'abcdef';
  2. echo strlen($str);

4.strrev — 反转字符串
strrev( string $string) : string
echo strrev("Hello world!");

5.str_repeat — 重复一个字符串
str_repeat( string $input, int $multiplier) : string
echo str_repeat("-=", 10);

6.addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符
addcslashes(要转义的字符串,转义字符的范围) : string
echo addcslashes('foo[ ]', 'A..z');

7.addslashes — 使用反斜线引用字符串
addslashes( string $str) : string

  1. $str = "Is your name O'reilly?";
  2. echo addslashes($str);

8.rtrim — 删除字符串末端的空白字符(或者其他字符)

  1. //rtrim( string $str, string $character_mask = ?) : string
  2. $trimmed = rtrim($hello, "Hdle");

9.strip_tags — 从字符串中去除 HTML 和 PHP 标记
strip_tags( string $str,指定不被去除的字符列表) : string

10.strtolower — 将字符串转化为小写

  1. //strtolower( string $string) : string
  2. $str = "Mary Had A Little Lamb and She LOVED It So";
  3. $str = strtolower($str);

11.strtoupper — 将字符串转化为大写

  1. // strtoupper( string $string) : string
  2. $str = "Mary Had A Little Lamb and She LOVED It So";
  3. $str = strtoupper($str);

// 12.trim — 去除字符串首尾处的空白字符(或者其他字符)

  1. $hello = " Hello Worl ";
  2. trim($hello, "Hdle");
  3. var_dump($trimmed);

13.ucfirst — 将字符串的首字母转换为大写

  1. $foo = 'hello world!';
  2. $foo = ucfirst($foo);

14.ucwords — 将字符串中每个单词的首字母转换为大写

  1. //ucwords( string $str, string $delimiters = " \t\r\n\f\v" ) : string
  2. $foo = 'hello world!';
  3. $foo = ucwords($foo);

15.ucfirst — 将字符串的首字母转换为大写
将 str 的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串。

  1. $foo = 'hello world!';
  2. $foo = ucfirst($foo);

16.strtolower — 将字符串转化为小写

  1. // 将 string 中所有的字母字符转换为小写并返回。
  2. $str = "Mary Had A Little Lamb and She LOVED It So";
  3. $str = strtolower($str);

17.strtoupper — 将字符串转化为大写

  1. //将 string 中所有的字母字符转换为大写并返回
  2. $str = "Mary Had A Little Lamb and She LOVED It So";
  3. $str = strtoupper($str);

18 lcfirst — 使一个字符串的第一个字符小写

  1. // 返回第一个字母小写的 str ,如果是字母的话
  2. $foo = 'HelloWorld';
  3. $foo = lcfirst($foo);

19 htmlspecialchars — 将特殊字符转换为 HTML 实体

  1. $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
  2. echo $new;

20 strcmp — 二进制安全字符串比较

  1. //strcmp( string $str1, string $str2) : int
  2. //如果 str1 小于 str2 返回 < 0;如果 str1 大于 str2 返回 > 0;如果两者相等,返回 0。
  3. $var1 = "Hello";
  4. $var2 = "hello";
  5. if (strcmp($var1, $var2) !== 0) {
  6. echo '$var1 is not equal to $var2 in a case sensitive string comparison';
  7. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post