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. Quote Link to comment 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"; Quote Link to comment Share on other sites More sharing options...
peter_anderson Posted May 3, 2010 Author Share Posted May 3, 2010 Thanks merylvingien Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.