3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $searchTerm = "abcd"; $replaceTerm = "XXXX"; $test=array("${searchTerm}/${searchTerm}_.${searchTerm}", "xay${searchTerm}", "asdasd/${searchTerm}.mp3", "${searchTerm}.", "blahahbasd${searchTerm}", "1234${searchTerm}1234"); foreach ($test as $t) echo "$t => " . preg_replace("/(". preg_quote($searchTerm) . "([^_.])|". preg_quote($searchTerm) . "$)/x", preg_quote($replaceTerm) . "\${2}", $t) . "\n";
Output for 4.3.0 - 7.1.0
abcd/abcd_.abcd => XXXX/abcd_.XXXX xayabcd => xayXXXX asdasd/abcd.mp3 => asdasd/abcd.mp3 abcd. => abcd. blahahbasdabcd => blahahbasdXXXX 1234abcd1234 => 1234XXXX1234