php截取字符串中指定两个字符中间的部分

方法1:

$str = "https://a.m.taobao.com/i592404572191.htm?price=26.9-89&sourceType=item&detailSharePosition=interactBar&sourceType=item&suid=196360d0-e48f-41e1-b265-3e3024c6672e&shareUniqueId=2016960869&ut_sk=1.WpFnOuc%2BOYMDACuqCza43AYq_21646297_1595498155982.TaoPassword-WeiXin.1&un=379afb76b45f9891d707d2abce2ca380&share_crt_v=1&spm=a2159r.13376460.0.0&sp_tk=ZVJJeTFBUHNuNGg=&bxsign=tcd1595568829738e66ee1e06b69c9bfc5c8a02d1393c408";

$str = substr($str,0,strpos($str, '.htm'));//截取 .htm 前面的内容
$str = trim(strrchr($str, 'com/i'),'com/i');//截取 com/i 后面的内容

结果:592404572191

方法2:

$str = "https://a.m.taobao.com/i592404572191.htm?price=26.9-89&sourceType=item&detailSharePosition=interactBar&sourceType=item&suid=196360d0-e48f-41e1-b265-3e3024c6672e&shareUniqueId=2016960869&ut_sk=1.WpFnOuc%2BOYMDACuqCza43AYq_21646297_1595498155982.TaoPassword-WeiXin.1&un=379afb76b45f9891d707d2abce2ca380&share_crt_v=1&spm=a2159r.13376460.0.0&sp_tk=ZVJJeTFBUHNuNGg=&bxsign=tcd1595568829738e66ee1e06b69c9bfc5c8a02d1393c408";

$b = mb_strpos($str,'com/i') + mb_strlen('com/i');
$e = mb_strpos($str,'.htm') - $b;
ehco mb_substr($str,$b,$e);

结果:592404572191

均亲测!!!

你可能感兴趣的:(php)