将EM标签转换为链接



标题很清楚。

我如何转换此迷你文章

Test article here. This is a <em>test test</em> article.
This is the other <em>line</em>.

php

Test article here. This is a <a href="http://stackoverflow.com/test test">test test</a> article.
This is the other <a href="http://stackoverflow.com/line">line</a>.

尝试以下:

$code = preg_replace('!<em>(.+?)</em>!', '<a href="http://stackoverflow.com/1">1</a>', $code);

这在jQuery中,以防万一:

$("em").wrap("<a href='http://stackoverflow.com/"+$("em").html()+"'></a>");
$("em").contents().unwrap();

最新更新