danglam Posted January 19, 2011 Share Posted January 19, 2011 Hello everybody. Have a good day. I'm Lam, I have problem hope you help me. 1. This is content html <img src="http://example.com/logo.png" /> anti http://google.com<br /> and http://bing.com I want convert to <img src="http://example.com/logo.png" /> anti <a href="http://google.com">http://google.com</a><br /> and <a href="http://bing.com">http://bing.com</a> and this code php preg_replace("/(http:\/\/[a-zA-Z-0-9._?\/\s]+)/", "<a href=\"$1\">$1</a>", $content); but result <img src="[color=red]<a href="http://example.com/logo.png">http://example.com/logo.png</a>[/color]" /> anti <a href="http://google.com">http://google.com</a><br /> and <a href="http://bing.com">http://bing.com</a> I can help me :'( I speak English not well hope u ignoring thanks. Link to comment https://forums.phpfreaks.com/topic/224900-help-convert-urls-to-link-in-content-have-tag-html/ Share on other sites More sharing options...
sasa Posted January 19, 2011 Share Posted January 19, 2011 try preg_replace("/( |>)(http:\/\/[a-zA-Z-0-9._?\/\s]+)/", " <a href=\"$2\">$2</a>", $test); or preg_replace("/[^\"'=](http:\/\/[a-zA-Z-0-9._?\/\s]+)/", "<a href=\"$1\">$1</a>", $content); Link to comment https://forums.phpfreaks.com/topic/224900-help-convert-urls-to-link-in-content-have-tag-html/#findComment-1161824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.