Pregunta

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>.
¿Fue útil?

Solución

Try this:

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

Otros consejos

this is in jquery just in case:

$("em").wrap("<a href='http://stackoverflow.com/"+$("em").html()+"'></a>");
$("em").contents().unwrap();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top