lulu: Regulärer Ausdruck gesucht: & in URL's umwandeln

Beitrag lesen

Huhu e7

mit look ahead geht es eigentlich ganz einfach, auch wenn
das keine Performance Wunder vollbringen wird.

$regexp = "/(&)(?![^>]+(<|$))/i";

Hier mal ein vollständiges Beispiel
<?php

$test = <<<EOT

&mdash; <a href="http://www.0815.net?a=12&b=12&c=13">Test GmbH &amp; Co KG </a>

& bei Bildern &nbsp;

<img src="thumbnail.php?x=12&y=400">

& wieso soll das nicht gehen?

EOT;

$regexp = "/(&)(?![^>]+(<|$))/i";

$new = preg_replace ($regexp, '&amp;', $test);

echo $new;

?>

Viele Grüße

lulu

--
bythewaythewebsuxgoofflineandenjoytheday