3v4l.org

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

preferences:
130.66 ms | 406 KiB | 5 Q