سؤال

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