How do I replace a single question mark with preg replace.
+2
A:
If it's a single character you're replacing, you may not need a preg_ solution: a "simple" str_replace may do the trick as well:
Bart Kiers
2009-08-18 20:33:17
A:
If you want to make sure not to replace either question mark in the string testing ??
you could do:
// using negative lookbehind/ahead to ensure that the question mark
// doesn't have a "friend"
$new = preg_replace('/(?<!\?)\?(?!\?)/', 'replacement', $original);
If you are looking to only replace the first question mark in the string - chaos's answer is what you want
gnarf
2009-08-18 21:10:41