在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
// 用preg_match 模仿实现 preg_match_all function custom_preg_match_all($pattern, $subject) { $offset = 0; $match_count = 0; while(preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset)) { // Increment counter $match_count++; // Get byte offset and byte length (assuming single byte encoded) $match_start = $matches[0][1]; $match_length = strlen($matches[0][0]); // (Optional) Transform $matches to the format it is usually set as (without PREG_OFFSET_CAPTURE set) foreach($matches as $k => $match) $newmatches[$k] = $match[0]; $matches = $newmatches; // Your code here echo "Match number $match_count, at byte offset $match_start, $match_length bytes long: ".$matches[0]."\r\n"; // Update offset to the end of the match $offset = $match_start + $match_length; } return $match_count; } 正则匹配练习: 文本源: <div>2</div> 2<div>1</div>abcd 模式1: 对于模式2,如果文本源变为:
|
2022-08-16
2022-11-06
2022-08-18
2022-08-15
2022-08-18
请发表评论