php - Automatically Mark Up HTML Text -
i hoping find way automatically mark html document based on text matches. have directory containing several hundred short html documents, contents of individually included (via php) in base_document.html depending on value of variable taken url, so:
<?php include $_get['id'] . ".html";?>
if included html document contains specific word, e.g. "dangerous," automatically format particular markup; example:
<strong>dangerous</strong>
is there particular library or function in php, javascript, and/or css provides kind of functionality? or need write own code achieve purpose?
edit: there long list of target words , associated markups, assume need refer custom dictionary residing in either file or database. e.g.,
"dangerous",bold "important",style:color=red "hungry",em "hot",strong
this example, must adapt case:
<?php $data[] = 'dangerous,bold'; $data[] = 'important,style:color=red'; $data[] = 'hungry,em'; $data[] = 'hot,strong'; $string = 'they dangerous , hungry think hot talk this.'; for($i = 0; $i < count($data); $i++) { $line = explode(',', $data[$i]); $string = str_replace($line[0], "<{$line[1]}>{$line[0]}</{$line[1]}>", $string); } echo $string; ?>
output:
they <bold>dangerous</bold> , <em>hungry</em> think <strong>hot</strong> talk this.
Comments
Post a Comment