PHP截取指定两个字符之间的字符串

PHP / 609人浏览 / 0人评论

php字符串截取,想要使用php编程脚本语言截取字符串之间的内容,比如我们想要在(www.xxxxxxxx.com),括号中截取www.和.com之间的xxxxxxxx内容。

PHP字符串截取

截取字符串指定前后之间的内容。

php字符串截取,想要使用php编程脚本语言截取字符串之间的内容,比如我们想要在(www.xxxxxxxx.com),括号中截取www.和.com之间的xxxxxxxx内容。

字符串函数:mb_strpos()mb_strlen()mb_substr()

案例需求

截取www.fxzbcn.com字符串之间的fxzbcn

要处理字的符串

www.fxzbcn.com
$start_strings = "www."; // 开始字符串
$end_strings = ".com"; // 结尾字符串
$strings = "www.dianthink.com"; // 字符串
$strings = self::cut_middle_strings($start_strings, $end_strings, $strings); // 处理函数调用
var_dump($strings); // 打印返回结果
//截取指定两个字符之间的字符串
public static function cut_middle_strings($begin = "", $end = "", $strings = ""){
    
    if (empty($begin) or empty($end) or empty($strings)) {
        return false;
    }
    
    $b = mb_strpos($strings, $begin) + mb_strlen($begin);
    
    $e = mb_strpos($strings, $end) - $b;

    return mb_substr($strings, $b, $e);
    
}

转载注明:

0 条评论

还没有人发表评论

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我