Aşağıdaki doReplace işlevi, nasıl ben $ anahtar kelime örneği adında html etiketleri bir dizinin herhangi bir (h1, h2, h3, h4, h5, h6, b, u, i, vb) bir çocuk olup olmadığını belirlemek istiyorum anahtar kelime içeriği görünür değiştirme noktasından? Ben bu noktada iç içe etiketleri kontrol etmek umurumda değil.
Bazı özyineleme deReplace işlevi içinde, yer olacağını düşünüyorum.
function doReplace($keyword)
{
//if(!is_keyword_in_named_tag())
return ' <b>'.trim($keyword).'</b>';
}
function init()
{
$content = "This will be some xhtml formatted
content that will be resident on the page in memory";
$theContent =
preg_replace_callback("/\b('my test string')\b/i","doReplace", $content);
return $theContent;
}
Yani $ içeriği değişken varsa ...
<h1>This is my test string</h1>
Sonra dize "benim test dize" olmazdı yerini.
Ama # content değişken içeriyorsa ...
<h1>This is my test string</h1>
<div>This is my test string too <b>my test string 3</b></div>
Sonra yerini içerik olurdu ...
<h1>This is my test string</h1>
<div>This is <b>my test string</b> too <b>my test string 3</b></div>