3v4l.org

run code in 300+ PHP versions simultaneously
<?php $My_String = preg_replace("/\h+/", "[\h-]+", "alpha beta gamma delta"); $strings = [ "My codephrase is alPha Beta-GaMMa deLTa and your codephrase is ALpha-beTA gAmmA-DElta", "alpha beta gamma delta", "alpha beta gamma-delta", "alpha beta-gamma delta", "alpha beta-gamma-delta", "alpha-beta gamma delta", "alpha-beta gamma-delta", "alpha-beta-gamma delta", "alpha-beta-gamma-delta", "alpha-beta-gamma-d" ]; foreach ($strings as $str) { $str = preg_replace("/\b$My_String\b/i", "<strong>$0</strong>", $str); echo $str . PHP_EOL; }
Output for 7.3.0 - 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.25, 8.4.1 - 8.4.12
My codephrase is <strong>alPha Beta-GaMMa deLTa</strong> and your codephrase is <strong>ALpha-beTA gAmmA-DElta</strong> <strong>alpha beta gamma delta</strong> <strong>alpha beta gamma-delta</strong> <strong>alpha beta-gamma delta</strong> <strong>alpha beta-gamma-delta</strong> <strong>alpha-beta gamma delta</strong> <strong>alpha-beta gamma-delta</strong> <strong>alpha-beta-gamma delta</strong> <strong>alpha-beta-gamma-delta</strong> alpha-beta-gamma-d

preferences:
128.88 ms | 408 KiB | 5 Q