<?php
$input = <<< TXT
Blah
Diddel
Foo
Bar1
Bar2
One
XXY
Password%1 = something
Password%2 = other
Password%3 = nuffing
Completely different stuff here
RandomS6}=2
User%1 = Henry
User%2 = Marcus
User%3 = SecretAdmin
More stuff
Even more stuff
Loads of stuff
TXT;
$matches = [];
$string = preg_replace_callback(
'~^(?>User.+|Password.+|XXY)$~m',
function ($match) use (&$matches) {
@$matches[substr($match[0], 0, 4)] .= $match[0].PHP_EOL;
return null;
},
$input
);
print_r(array_merge($matches, preg_split('/^\s+$/m', $string)));
- Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- Array
(
[XXY] => XXY
[Pass] => Password%1 = something
Password%2 = other
Password%3 = nuffing
[User] => User%1 = Henry
User%2 = Marcus
User%3 = SecretAdmin
[0] => Blah
Diddel
Foo
Bar1
Bar2
One
[1] =>
Completely different stuff here
RandomS6}=2
[2] =>
More stuff
Even more stuff
Loads of stuff
)
preferences:
135.06 ms | 409 KiB | 5 Q