sözlüğü olan kelime tanımları göstermek için çalışıyor

0 Cevap php

I'm trying to use regex to parse some plain text and add a definition from a glossary to any words that match it. I'm doing it like this:

for ( $i = 0; $i < count($terms); $i++ ) {
    $search = '|(?<=\b)('.preg_quote($terms[$i]['title']).')(?=\b)|i';
    $replace = '<a class="tt2" rel="tooltip" title="'.$terms[$i]['pageBody'].'">$1</a>';
    $string = preg_replace($search,$replace,$string);
}

I then return $string, however if one of the definitions contains a word which is defined later then the definition gets added to that also, so I want to no include words that are within the title="". I've tried putting (?!<=title=") but that doesn't work if the definition is multiple words and the match is not the first word.

Herhangi bir fikir?

örnek giriş metni:

40.000 üzerinde fosiller, kayalar ve mineraller Devon manzara son 490 milyon yılda gördü hayati değişikliklerin kanıtıdır. 4.5 milyon yaşında göktaşı gezegenimizin ilk günlerinde bir soydan olduğunu. Ichthyosaur iskeletler büyük sürüngenler okyanusları hakim ve dinozorlar arazi idare bir süre temsil eder. Mamut dişleri bugünkü manzara en gelişmiş özellikleri sırasında son Buz Çağı kalıntıları vardır.

0 Cevap