The title is clear.

How can I convert this mini article

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

to that by 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>.
有帮助吗?

解决方案

Try this:

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

其他提示

this is in jquery just in case:

$("em").wrap("<a href='http://stackoverflow.com/"+$("em").html()+"'></a>");
$("em").contents().unwrap();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top