开发者

PHP REGEX preg_match_all every line after a particular line

开发者 https://www.devze.com 2023-02-21 20:53 出处:网络
Here is the sample string with my regex and code: $str = \"Supp Fees: ---------- Oral Glucose Glucagon OXYGEN\";

Here is the sample string with my regex and code:

$str = "Supp Fees:
----------
Oral Glucose
Glucagon
OXYGEN";

$ptn = "/----------(?:\r\n(.+))+/m";
preg_match_all($ptn,$str,$matches);

echo"<pre>";
print_r($matches);
echo"</pre>";

I'm trying to match every line after '----------' the pattern above only returns the 开发者_开发问答first line (Oral Glucose). I can repeat the '\r\n(.+)' part and return another line but there is no telling how many lines there will be.

Thanks!


You could do this without regex:

$data = substr($str, strpos($str, '----------') + 10);
$matches = explode("\r\n", $data);


<?php

$str = "Supp Fees:
----------
Oral Glucose
Glucagon
OXYGEN";


$str = explode('----------', $str);
preg_match_all("/[^\r\n].*/", $str[1], $matches);

echo"<pre>";
print_r($matches);
echo"</pre>";

?>

?

0

精彩评论

暂无评论...
验证码 换一张
取 消