开发者

How to automatically add tags to plain text data?

开发者 https://www.devze.com 2023-01-18 21:03 出处:网络
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

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

精彩评论

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

关注公众号