时间:2021-07-01 10:21:17 帮助过:63人阅读
PHP采集利器:根据开始字符串和结束字符串截取需要的采集内容数据
function strCutByStr(&$str, $findStart, $findEnd = false, $encoding = 'utf-8'){ if(is_array($findStart)){ if(count($findStart) === count($findEnd)){ foreach($findStart as $k => $v){ if(($result = strCutByStr($str, $v, $findEnd[$k], $encoding)) !== false){ return $result; } } return false; }else{ return false; } } if(($start = mb_strpos($str, $findStart, 0, $encoding)) === false){ return false; } $start += mb_strlen($findStart, $encoding); if($findEnd === false){ return mb_substr($str, $start, NULL, $encoding); } if(($length = mb_strpos($str, $findEnd, $start, $encoding)) === false){ return false; } return mb_substr($str, $start, $length - $start, $encoding); }
举例:
$str = '1那是一场23我问问4567890维稳'; echo (strCutByStr($str, '那是', '稳'));//输出 一场23我问问4567890维
http://www.bkjia.com/PHPjc/914775.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/914775.htmlTechArticlePHP采集利器:根据开始字符串和结束字符串截取需要的采集内容数据 PHP采集利器:根据开始字符串和结束字符串截取需要的采集内容数据...