2014-01-23 6 views
1

제목이 분명합니다.em 태그를 링크로 변환

어떻게 PHP에 의해 그이 미니 기사

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

을 변환 할 수 있습니다

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>. 
+0

여기서'href'의 값은 어디서 왔습니까? – dachi

+0

http://stackoverflow.com/questions/2139140/replace-non-html-links-with-a-tags?rq=1 –

+0

아주 잘 작동하는 em 태그 – Emre

답변

0

이 시도 :

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

의 내부 텍스트입니다. 감사합니다. – Emre

0

이 단지의 경우 JQuery와에 있습니다

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