3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extractWantedStuff($input) { $output = []; $sections = explode('""', $input); foreach ($sections as $key => $section) { if ($key % 2 != 0) { $section = str_replace(',', '', $section); } $output[] = $section; } return implode('""', $output); } $fullstring = ',""Word1, Word2"" and another thing ,""Word3, Word4""'; echo extractWantedStuff($fullstring);

preferences:
37.56 ms | 406 KiB | 5 Q