fert Posted December 15, 2006 Share Posted December 15, 2006 I have this code[code]function bbcode($comment){ $bb=array("'\[b\](.*?)\[/b\]'","'\[i\](.*?)\[/i\]'","'\[u\](.*?)\[/u\]'","'\[url=(.*?)\](.*?)\[/url\]'","'\[color=(.*?)\](.*?)\[/color\]'","'\[size=(.*?)\](.*?)\[/size\]'","'\[img\](.*?)\[/img\]'","'\[quote\](.*?)\[/quote\]'","'\[spoiler\](.*?)\[/spoiler\]'","'\[code\](.*?)\[/code\]'","'\[center\](.*?)\[/center\]'","'\[sub\](.*?)\[/sub\]'","'\[sup\](.*?)\[/sub\]'"); $replace=array("<b>$1</b>","<i>$1</i>","<u>$1</u>","<a href=\"$1\">$2</a>","<font color=\"$1\">$2</font>","<font size=\"$1\">$2</font>","<a href=\"$1\"><img scr=\"$1\" alt=\"Posted image\"></a>","<textarea readonly rows=\"5\" cols=\"40\">Quote:\n$1</textarea>","<font color=\"#FFFFFF\">$1</font>","<textarea rows=\"5\" cols=\"30\" readonly>Code:\n$1</textarea>","<p align=\"center\">$1</p>","<sub>$1</sub>","<sup>$1</sup>"); $comment=preg_replace($bb,$replace,$comment); $comment=str_replace("[list]","<ul>",$comment); $comment=str_replace("[*]","<li>",$comment); $comment=str_replace("[/*]","</li>",$comment); $comment=str_replace("[list=1]","<ol>",$comment); $comment=str_replace("[/list]","</ol></ul>",$comment); return $comment;}[/code]This is a function to replace BBcode in a blog entry, but any tag beyond [ quote] doesn't work and there are no errors produced. any ideas as to why it doesn't work? Quote Link to comment Share on other sites More sharing options...
fert Posted December 16, 2006 Author Share Posted December 16, 2006 *bump Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 16, 2006 Share Posted December 16, 2006 Try this slight reformat of $bb & $replace[code] $bb=array('/\[b\](.*?)\[/b\]/','/\[i\](.*?)\[/i\]/','/\[u\](.*?)\[/u\]/','/\[url=(.*?)\](.*?)\[/url\]/','/\[color=(.*?)\](.*?)\[/color\]/','/\[size=(.*?)\](.*?)\[/size\]/','/\[img\](.*?)\[/img\]/','/\[quote\](.*?)\[/quote\]/','/\[spoiler\](.*?)\[/spoiler\]/','/\[code\](.*?)\[/code\]/','/\[center\](.*?)\[/center\]/','/\[sub\](.*?)\[/sub\]/','/\[sup\](.*?)\[/sup\]/'); $replace=array("<b>$1</b>","<i>${0}</i>","<u>${0}</u>","<a href=\"${0}\">${1}</a>","<font color=\"${0}\">${1}</font>","<font size=\"${0}\">${1}</font>","<a href=\"${0}\"><img scr=\"${0}\" alt=\"Posted image\"></a>","<textarea readonly rows=\"5\" cols=\"40\">Quote:\n${0}</textarea>","<font color=\"#FFFFFF\">${0}</font>","<textarea rows=\"5\" cols=\"30\" readonly>Code:\n${0}</textarea>","<p align=\"center\">${0}</p>","<sub>${0}</sub>","<sup>${0}</sup>");[/code] Quote Link to comment Share on other sites More sharing options...
fert Posted December 16, 2006 Author Share Posted December 16, 2006 when i do that i get lots of warnings Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 16, 2006 Share Posted December 16, 2006 Oops. Try replacing all the outer double quotes (") with single quotes (') in the $replace array[code] $replace=array('<b>${0}</b>>','<i>${0}</i>','<u>${0}</u>','<a href="${0}">${1}</a>','<font color="${0}">${1}</font>','<font size="${0}">${1}</font>','<a href="${0}"><img scr="${0}" alt="Posted image"></a>','<textarea readonly rows="5" cols="40">Quote:${0}</textarea>','<font color="#FFFFFF">${0}</font>','<textarea rows="5" cols="30" readonly>Code:${0}</textarea>','<p align="center">${0}</p>','<sub>${0}</sub>','<sup>${0}</sup>');[/code] 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.