3v4l.org

run code in 500+ PHP versions simultaneously
<?php $chat = <<<CHAT <Amanda> Hi there, how are you? <Jack> Hi, im fine <Paul> sup yall <Petra> wasabi <Paul> shall we go for beers? <Petra> most definitely <Jack> see you later CHAT; preg_match_all( '/^<((?!Amanda>|Jack>)[^>]+)> \K.+/m', $chat, $matches, PREG_SET_ORDER ); $result = []; foreach ($matches as [$words, $name]) { $result[$name] = ($result[$name] ?? 0) + str_word_count($words); } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 'Paul' => 7, 'Petra' => 3, )

preferences:
77.86 ms | 1105 KiB | 4 Q