<?php
$veri = '<img src="http://www.aaaa.com/resim/aaaa.jpg">';
$veri2 = 'resim';


function CustomSTR($aranan,$degisen,$metin){
$sonuc = strpos($metin,"img");
if($sonuc === false){
return str_replace($aranan,$degisen,$metin);
}
}

echo CustomSTR('resim','<a href="resimler.net">resim</a>',$veri2);
echo CustomSTR('resim','<a href="resimler.net">resim</a>',$veri);

?>


--R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 14:41:13 -->-> Daha önceki mesaj 14:08:50 --

Sanırım işine bu yarayacak;

class replaceIfNotInsideTags {
 
  private function checkOpenTag($matches) {
    if (strpos($matches[0], '<') === false) {
      return $matches[0];
    } else {
      return '<a href="'.$matches[1].'">'.$matches[1].'</a>'.$this->doReplace($matches[2]);
    }
  }
 
  private function doReplace($html) {
   return preg_replace_callback('/(\b'.$this->word.'\b)(.*?>)/i',
                                 array(&$this, 'checkOpenTag'),
                                 $html);
  }
 
  public function replace($html, $word) {
    $this->word = $word;
 
    return $this->doReplace($html);
  }
}
 
$html = 'resim ve <img src="http://www.aaaa.com/resim/aaaa.jpg" />';
 
$obj = new replaceIfNotInsideTags();

echo $obj->replace($html, 'resim');