Noskiw Posted December 29, 2008 Share Posted December 29, 2008 <?php function topic($input){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>", "[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'>", " " => "</div>"); $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $input); return $parsedtext; return nl2br(strip_tags(stripslashes(htmlspecialchars($input)))); }?>[/code] but when i type in like html entities in the code tags, nothing shows up in the div, and when i use bbcode, i cant do a <br> (enter) " => "</div>"); that bit is meant to say "[/code]" => "</div>"); Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/ Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 for a line break you need to replace \n \r\n and \r with <br /> that will enter you're line breaks. With the [ code] tag problem, what do you want to be able to write inside? something along the lines of ?? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725282 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 what i mean like with the code that you get here but with no syntax highlighting. so like <html> </html> like that. Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725288 Share on other sites More sharing options...
redarrow Posted December 29, 2008 Share Posted December 29, 2008 done this a long time back have a look. <?php $var=" [code=php:0]<?php if(\$redarrow=='redarrow'){ echo \$redarrow; }?> "; function bbcode_format($var) { $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[smile1\](.*?)\[\/smile1\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile2\](.*?)\[\/smile2\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile3\](.*?)\[\/smile3\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile4\](.*?)\[\/smile4\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile5\](.*?)\[\/smile5\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile6\](.*?)\[\/smile6\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile7\](.*?)\[\/smile7\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile8\](.*?)\[\/smile8\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile9\](.*?)\[\/smile9\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[smile10\](.*?)\[\/smile10\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[red\](.*?)\[\/red\]/is', '/\[blue\](.*?)\[\/blue\]/is', '/\[green\](.*?)\[\/green\]/is', '#\ [php\](.*?)\[\/php\]#se', ); $replace = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<img src="$1" />', '<a href="$1">$1</a>', '<a href="$1">$2</a>', '<img src="$1" />', '<a href="$1">$3</a>', '<img src="$1" />', '<a href="$1">$4</a>', '<img src="$1" />', '<a href="$1">$5</a>', '<img src="$1" />', '<a href="$1">$6</a>', '<img src="$1" />', '<a href="$1">$7</a>', '<img src="$1" />', '<a href="$1">$8</a>', '<img src="$1" />', '<a href="$1">$9</a>', '<img src="$1" />', '<a href="$1">$10</a>', '<img src="$1" />', '<a href="$1">$11</a>', '<img src="$1" />', '<a href="$1">$12</a>', '<font color="red">$1</font>', '<font color="blue">$1</font>', '<font color="green">$1</font>', "'<div>'.highlight_string(('$1'), true).'</div>'", ); $var = preg_replace ($search, $replace, $var); return $var; } echo bbcode_format($var) ?> [/code] Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725290 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 how would i wrap the nl2br() around my array? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725317 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725388 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 one more problem url bbcode problem "[url]" => "<a href=''>", "[/url]" => "</a>" it goes to the same page, any suggestions? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725487 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 seriously, anyone? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725560 Share on other sites More sharing options...
Noskiw Posted December 29, 2008 Author Share Posted December 29, 2008 is anyone gonna help? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-725659 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 one more problem url bbcode problem "[url]" => "<a href=''>", "[/url]" => "</a>" it goes to the same page, any suggestions? same problem still. Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726056 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 one more problem url bbcode problem "[url]" => "<a href=''>", "[/url]" => "</a>" it goes to the same page, any suggestions? same problem still. anyone, seriously, i've gone through and through but, problems still. i don't know whats wrong. Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726100 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 your just changing it to an empty link -> <a href=''></a> its always going to just refresh the page. You need the bbcode to parse a url as well such as Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726105 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 which would be? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726106 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 are you not tempted to try and figure this out yourself? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726107 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 this my bbcode from a year or so ago, have a look through function bbcode($str) { $str = htmlentities($str); $basic_search = array('/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[lb\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[img\=(.*?)\]/is'); $basic_replace = array('<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<br>', '<a href="$1" target="_new" class="full">$2</a>', '<img src="$1" align="center" />'); $str = preg_replace($basic_search, $basic_replace, $str); return $str; } function reverse($str) { $str = str_replace('<br>', '[lb]', $str); $str = str_replace('<b>', '[b]', $str); $str = str_replace('</b>', '[/b]', $str); $str = str_replace('<i>', '[i]', $str); $str = str_replace('</i>', '[/i]', $str); $str = str_replace('<u>', '[u]', $str); $str = str_replace('</u>', '[/u]', $str); $str = str_replace('<img src="', '[img=', $str); $str = str_replace('" align="center" />', ']', $str); $str = str_replace('<a href="', '[url=', $str); $str = str_replace('" target="_new" class="full">', ']', $str); $str = str_replace('</a>', '[/url]', $str); return $str; } Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726108 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 the first function should do everything for you Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726110 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 this my bbcode from a year or so ago, have a look through function bbcode($str) { $str = htmlentities($str); $basic_search = array('/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[lb\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[img\=(.*?)\]/is'); $basic_replace = array('<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<br>', '<a href="$1" target="_new" class="full">$2</a>', '<img src="$1" align="center" />'); $str = preg_replace($basic_search, $basic_replace, $str); return $str; } function reverse($str) { $str = str_replace('<br>', '[lb]', $str); $str = str_replace('<b>', '[b]', $str); $str = str_replace('</b>', '[/b]', $str); $str = str_replace('<i>', '[i]', $str); $str = str_replace('</i>', '[/i]', $str); $str = str_replace('<u>', '[u]', $str); $str = str_replace('</u>', '[/u]', $str); $str = str_replace('<img src="', '[img=', $str); $str = str_replace('" align="center" />', ']', $str); $str = str_replace('<a href="', '[url=', $str); $str = str_replace('" target="_new" class="full">', ']', $str); $str = str_replace('</a>', '[/url]', $str); return $str; } is it possible to have a function inside a function? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726111 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 You can call other functions from inside a function, but there is no need to put a function inside another Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726113 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 how would i change your code into the format i was already using???? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726118 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 it uses preg_replace() because you want to get random strings from the input so I'd recommend just using that function and dumping yours. Test it first Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726121 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 ok, how do i convert my code tag? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726122 Share on other sites More sharing options...
gevans Posted December 30, 2008 Share Posted December 30, 2008 You're going to have to be moire specific with your questions Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726124 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 <?php function topic($input){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>", "[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'>", " " => "</div>"); $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $input); return $parsedtext; return nl2br(strip_tags(stripslashes(htmlspecialchars($input)))); }?>[/code] but when i type in like html entities in the code tags, nothing shows up in the div, and when i use bbcode, i cant do a <br> (enter) " => "</div>"); that bit is meant to say "[/code]" => "</div>"); how would i convert that? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726130 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 <?php function topic($input){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>", "[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'>", " " => "</div>"); $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $input); return $parsedtext; return nl2br(strip_tags(stripslashes(htmlspecialchars($input)))); }?>[/code] but when i type in like html entities in the code tags, nothing shows up in the div, and when i use bbcode, i cant do a <br> (enter) " => "</div>"); that bit is meant to say "[/code]" => "</div>"); how would i convert that? how would i convert it?hello? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726156 Share on other sites More sharing options...
Noskiw Posted December 30, 2008 Author Share Posted December 30, 2008 <?php function topic($input){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>", "[code]" => "<font style=\"padding:3px;\" color=\"#CC0000\" size=\"2\">Code:</font><br><div id='code'>", " " => "</div>"); $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $input); return $parsedtext; return nl2br(strip_tags(stripslashes(htmlspecialchars($input)))); }?>[/code] but when i type in like html entities in the code tags, nothing shows up in the div, and when i use bbcode, i cant do a <br> (enter) " => "</div>"); that bit is meant to say "[/code]" => "</div>"); how would i convert that? how would i convert it?hello? i still don't know someone help please? Link to comment https://forums.phpfreaks.com/topic/138726-bbcode-problems/#findComment-726211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.