PHP: replace characters and make exceptions (preg_replace)

brrrickt

New Member
How do I:
  • replace characters in a word using \[code\]preg_replace()\[/code\] but makean exception if they are part of acertain word.
  • replace an uppercase character with anuppercase replacement even if thereplacement is lowercase and viceversa.
example: \[code\]$string = 'Newton, Einstein and Edison. end'; echo preg_replace('/n/i', '<b>n</b>', $string); \[/code\]from: newton, Einstein and Edison. end
to: Newton, Einstein and Edison. endIn this case I want all the \[code\]n\[/code\] letters to be replaced unless they are part of the word \[code\]end\[/code\] And \[code\]Newton\[/code\] should not change to \[code\]newton\[/code\]
 
Back
Top