jreed121 jreed121 - 3 years ago 86
PHP Question

PHP REGEX preg_match_all every line after a particular line

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!

Answer Source

You could do this without regex:

$data = substr($str, strpos($str, '----------') + 10);
$matches = explode("\r\n", $data);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download