3v4l.org

run code in 150+ 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"; echo $str = str_replace_word('ann@ibbeck.de','kan',"ann@ibbeck.de,Petermann@ibbeck.de"); echo $str = str_replace_word('Petermann@ibbeck.de','AP',$str); ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
kan,Petermann@ibbeck.dekan,AP