这篇文章主要介绍了php如何截取指定字符之间字符串,有一定的参考价值,感兴趣的朋友可以看看,希望对你有所帮助!
/** * php截取指定两个字符之间字符串,默认字符集为utf-8 Power by 大耳朵图图 * @param string $begin 开始字符串 * @param string $end 结束字符串 * @param string $str 需要截取的字符串 * @return string */ function cut($begin,$end,$str){ $b = mb_strpos($str,$begin) + mb_strlen($begin); $e = mb_strpos($str,$end) - $b; return mb_substr($str,$b,$e); }
调用
echo $this->cut('token/','?code',$redirectUrl);die;
上面的方法不是很好用,当截取的是值为串的时候,会出现截取不到的情况用下面的吧
/* * php截取指定两个字符之间字符串 * */
function get_between($input, $start, $end) { $substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1)); return $substr; }
调用
$sVid = $this->get_between($redirectUrl, "token/", "?code=");
【相关教程推荐】
2. php从入门到精通
3. bootstrap教程

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
