Question

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>.
Was it helpful?

Solution

Try this:

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

OTHER TIPS

this is in jquery just in case:

$("em").wrap("<a href='http://stackoverflow.com/"+$("em").html()+"'></a>");
$("em").contents().unwrap();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top