How to automatically add tags to plain text data?
i'm making a recipe database, but i want a table for ingredients and for actions (i.e whisk) and when a user submits the plain text instructions i want it to wra开发者_Python百科p those keywords with div tags.
is there a similar app that does something like that?
Something like this should do the trick:
$text = 'this is a cooking test';
$keywords = array('cooking' => array('before' => '<span class="cooking">', 'after' => '</span>'));
foreach($keywords as $key => $value) {
$text = str_replace($key, $value['before'].$key.$value['after'], $text);
}
print $text;
this would produce:
this is a <span class="cooking">cooking</span> test
精彩评论