ChrisB: Nur bestimmte Zeichen ersetzten

Beitrag lesen

Hi,

Oh, das war der alte Ausdruck, so weit bin ich aber

print preg_replace("/([^[]'|'[^]])/", '’', $string);

Du brauchst Assertions, genauer (negative) Lookahead- und Lookbehind-Assertions, um dein ' nur zu finden, wenn davor kein [ und dahinter kein ] steht:

print preg_replace("/(?<!\[)'(?!\])/", '&#8217;', $string);

MfG ChrisB

--
"The Internet: Technological marvel of marvels - but if you don't know *what* you're lookin' for on the Internet, it is nothing but a time-sucking vortex from hell."