peter_anderson Posted May 3, 2010 Share Posted May 3, 2010 I'm coding a php forum script mod, but I do not know how to do the URL bbCode. I want to do two versions: 1) Example: [url]http://example.com[/url] The script should search for [url ] (space added to stop the board parsing it) and replace it with: <a href="URL" target="_blank" title="External link">URL</a> 2) The script should look for all URLs (http://) and replace it with: <a href="URL" target="_blank" title="External link">URL</a> I'm thinking that preg_replace and regex would do, but I'm unsure as to how. Can anyone advise? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/200583-link-bbcode-url/ Share on other sites More sharing options...
merylvingien Posted May 3, 2010 Share Posted May 3, 2010 $simple_search = array( '/\[url\](.*?)\[\/url\]/is', ); $simple_replace = array( '<a href="$1" target="_blank" title="$1">$1</a>', ); $post = preg_replace ($simple_search, $simple_replace, $post); echo "$post"; Link to comment https://forums.phpfreaks.com/topic/200583-link-bbcode-url/#findComment-1052529 Share on other sites More sharing options...
peter_anderson Posted May 3, 2010 Author Share Posted May 3, 2010 Thanks merylvingien Link to comment https://forums.phpfreaks.com/topic/200583-link-bbcode-url/#findComment-1052562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.