3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function str_replace_word($needle,$replacement,$haystack){ $pattern = "/\b$needle\b/i"; $haystack = preg_replace($pattern, $replacement, $haystack); return $haystack; } $str = "ann@ibbeck.de,Petermann@ibbeck.de"; $str = str_replace_word('ann@ibbeck.de','kan',"ann@ibbeck.de,Petermann@ibbeck.de"); $str = str_replace_word('Petermann@ibbeck.de','AP',$str); ?>
Output for 4.3.0 - 7.2.0