<?php $str = 'his'; $s1 = 'hi';$s2 = 's'; $result = preg_replace('~' . preg_quote($s1) . '(?!' . preg_quote($s2) . ')~', 'replace with this', $str); var_dump($result);
Standard input is empty
string(3) "his"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!