开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜