Bu PHP fonksiyonu üzerinde çalışıyorum. Fikir (bir dizide verilen iki, kelime ve etiketleri,) belirli etiketleri içine bir dize meydana gelen bazı kelimeleri sarılmasıdır. Bu! Tamam çalışır, ancak bu kelimeler bir bağlantılı metin ya da 'src' niteliğine meydana geldiğinde, o zaman tabii bağlantı kırık ve etiketleri ile doldurulmuş, ya da bir bağlantı içinde olmamalıdır etiketleri oluşturulur. Bu şimdi ne var:
function replace() {
$terminos = array (
"beneficios" => "h3",
"valoracion" => "h2",
"empresarios" => "h2",
"tecnologias" => "h2",
"...and so on..." => "etc",
);
foreach ($terminos as $key => $value)
{
$body = "string where the word empresarios should be replaced; but the word <a href='http://www.empresarios.com'>empresarios</a> should not be replaced inside <a> tags nor in the URL of their 'src' attribute.";
$tagged = "<".$value.">".$key."</".$value.">";
$result = str_replace($key, $tagged, $body);
}
}
Bu fonksiyon, bu örnekte, döndürmelidir "string where the word <h2>empresarios</h2> should be replaced; but the word <a href='http://www.empresarios.com'>empresarios</a> should not be replaced inside <a> tags nor in the URL of their 'src' attribute."
Ben dize düşünce tüm bu iş için yedek işlevi gibi, ama onun nitelikleri değil içeride etiketleri nor! Ediyorum
(Ben bunu ne gerek javascript olmadığını sadece, aşağıdaki parçacığı belirtilen ne yapmak isterdim, ama PHP: /questions/1666790/how-to-replace-text-not-within-a-specific-tag-in-javascript
)