EchoFool Posted July 21, 2010 Share Posted July 21, 2010 Hey, I am trying to use my function replace urls into <A href=""> in the array but do not know how i would do it with the current function i am using for my BBCode.... Say a user types www.google.com i want it to be clickable in the post. My BBCode function is: <?php //bb code fucntion function BBCodechat($BB){ $BBCode = array("&" => "&", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>" ); $Message = str_ireplace(array_keys($BBCode), array_values($BBCode), $BB); return $Message; } ?> Hope you can help. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 21, 2010 Author Share Posted July 21, 2010 bump Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 22, 2010 Author Share Posted July 22, 2010 bump Quote Link to comment Share on other sites More sharing options...
phpretard Posted July 22, 2010 Share Posted July 22, 2010 Have you looked through this? http://theserverpages.com/php/manual/en/function.preg-replace.php Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 22, 2010 Author Share Posted July 22, 2010 woah that looks confusing, is my BBCode function not the best approach then Quote Link to comment Share on other sites More sharing options...
phpretard Posted July 22, 2010 Share Posted July 22, 2010 This one in particular looked fitting to me. <?php function change_string($str) { $str = trim($str); $str = htmlspecialchars($str); $str = preg_replace('#(.*)\@(.*)\.(.*)#','<a href="mailto:\\1@\\2.\\3">Send email</a>',$str); $str = preg_replace('=([^\s]*)(www.)([^\s]*)=','<a href="http://\\2\\3" target=\'_new\'>\\2\\3</a>',$str); return $str; } ?> Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 22, 2010 Author Share Posted July 22, 2010 Yeh but that i cannot include in my BBCode function can i cos its different functions...? Quote Link to comment Share on other sites More sharing options...
phpretard Posted July 22, 2010 Share Posted July 22, 2010 You mean this? <?php function BBCodechat($BB) { $str = trim($BB); $str = htmlspecialchars($BB); $str = preg_replace('#(.*)\@(.*)\.(.*)#','<a href="mailto:\\1@\\2.\\3">Send email</a>',$BB); $str = preg_replace('=([^\s]*)(www.)([^\s]*)=','<a href="http://\\2\\3" target=\'_new\'>\\2\\3</a>',$BB); return $BB; } ?> Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 22, 2010 Author Share Posted July 22, 2010 No because then these: "&" => "&", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>" Won't be included ... Quote Link to comment Share on other sites More sharing options...
mattal999 Posted July 22, 2010 Share Posted July 22, 2010 Do this then: function BBCodechat($BB){ $BBCode = array("&" => "&", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>" ); $Message = str_ireplace(array_keys($BBCode), array_values($BBCode), $BB); $Message = trim($Message); $Message = htmlspecialchars($Message); $Message = preg_replace('#(.*)\@(.*)\.(.*)#','<a href="mailto:\\1@\\2.\\3">Send email</a>',$Message); $Message = preg_replace('=([^\s]*)(www.)([^\s]*)=','<a href="http://\\2\\3" target=\'_new\'>\\2\\3</a>',$Message); return $Message; } 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.