Blogger Information
Blog 19
fans 0
comment 1
visits 19501
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP截取指定字符[【前面】和【后面】的内容
TANKING的代码日志
Original
1261 people have browsed it

1.PHP截取指定字符【后面】的内容

使用函数 strripos() 获取一个字符串在另一个字符串中第一次出现的位置。

中文字符串使用 mb_strripos()

  1. $str = 'ABC-DEF';
  2. $ret = substr($str, strripos($str, "-") + 1);
  3. echo $ret; // 输出 DEF

2.PHP截取指定字符【前面】的内容

使用函数 strrops() 获取一个字符串在另一个字符串中最后一次出现的位置。

中文字符串使用 mb_strrops()

  1. $str = 'ABC-DEF';
  2. $ret = substr($str, 0, strrpos($str, "-"));
  3. echo $ret; // 输出 ABC
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