方法一:
使用 strrpos、substr
strrpos() 函数查找字符串在另一字符串中最后一次出现的位置(区分大小写)
$subject ='=HYPERLINK("https://www.iesdouyin.com/share/video/7218154606591806724/?mid=7212902668738152505&schema_type=37","https://www.iesdouyin.com/share/video/7218154606591806724/?mid=7212902668738152505&schema_type=37")';
$start = 'HYPERLINK("';
$end = '",';
$startIndex = strrpos($subject, $start)+strlen($start);
$endIndex = strrpos($subject, $end)-strlen($start)-1;
$str = substr($subject, $startIndex, $endIndex);
echo $str;exit;
输出:
https://www.iesdouyin.com/share/video/7218154606591806724/?mid=7212902668738152505&schema_type=37
方法二:
正则匹配
$pattern = '/(http|https):\/\/(www)\.([^\.\/]+)\.(com|net|org)(\/([\w]+))+(\/\?)*(([\w]+)=([\w]+)(&([\w]+)=([\w]+))*)*/i';
$subject = '=HYPERLINK("https://www.iesdouyin.com/share/video/7218730494597352719/?mid=7087441957509318692&schema_type=37","#我的抖音生活日记 [烟花]君乐宝#诠臻爱新客活动来啦
[庆祝]新客首购1听➕99元
[福]同品大听奶粉包邮到家
活动时间:23年4月1日-23年5月31日
❤大家快来参与吧 新冠疫情过后国家都提倡提高免疫力 自护力")';
preg_match($pattern, $subject, $matches);
echo $matches[0]?? '';exit;
输出
https://www.iesdouyin.com/share/video/7218730494597352719/?mid=7087441957509318692&schema_type=37