ups, hab das mit den anderen Tags überlesen :P
hier nochmal richtig:
<?php
####### $content ist der zu verarbeitende Text, woher auch immer der kommt
$content = 'asdas <img title="Test" /> Test dasd <span><a href="">Test</a> Test <a href="">asd Test</a></span>';
$subChar = chr(26); // ASCII substitution character
preg_match_all("@(<a[^>]*>(.*?)</a>)|(<[^a][^>]*>)@", $content, $matches);
if (!empty($matches[0])) {
$links = $matches[0];
$linkPatterns = array();
for($i=0; $i<sizeof($links); $i++) {
// why isn't quotemeta escaping the "/" characters?
$linkPatterns[$i] = "/".preg_replace("///", "\/", quotemeta($links[$i]))."/";
}
$content = preg_replace($linkPatterns, $subChar, $content, 1);
}
####### Hier kommen deine eigenen Ersetzungen hin
$content = str_replace('Test', 'Test2', $content);
if (!empty($matches[0])) {
$content = preg_replace(array_fill(0, sizeof($links), "/".$subChar."/"), $links, $content, 1);
}
####### Was dann wohl mit dem Content gemacht wird?
echo $content;
?>
Hoffe das hilft.
Gruß,
Niklas