php_begins Posted September 22, 2011 Share Posted September 22, 2011 My BBCODE makes the <img> tag inactive. For example, when I have an <img>tag such as: <br><img width='400' src='http://www.petergrand.com/deck.jpg'><br> It should display that image but it doesn't when I call with my BBCodeToHTML function. Here is my bbcode ..can it be modified without affecting other pages? <style type="text/css"> /* Syntax Highlight Code Box */ .linenum{ text-align:right; background:#FDECE1; border:1px solid #cc6666; padding:18px 1px 18px 1px; font-family:Courier New, Courier; float:left; width:17px; margin:3px 0px 30px 0px; } code {/* safari/konq hack */ font-family:Courier New, Courier; margin:0; padding:0; } .linetext{ width:700px; text-align:left; background:white; border:1px solid #cc6666; border-left:0px; padding:0px 1px 0px 8px; font-family:Courier New, Courier; float:left; margin:3px 0px 30px 0px; } br.clear { clear:both; } </style> <?php function printCode($code, $lines_number = 0,$title='Code: ') { $break = ' '; if (!is_array($code)) $codeE = explode($break, $code); $count_lines = count($codeE); $r = '<div style="margin-bottom: 2px;font-size:10px;font-family:sans-serif">' .$title .'</div>'; if ($lines_number) { $r .= '<div class="linenum">'; for($i=1;$i<=$count_lines;$i++) { $r .= $i.'<br />'; } $r .= '</div>'; } $r .= '<div class="linetext">'; $r .= highlight_string($code,1); $r .= (strpos($code,'<?php')===false?$break:''); $r .= '</div>'; return '<div class="code">'.$r.'</div>'; } function BBCodeToHTML($text) { $text = trim(htmlentities($text)); if(!function_exists('php_box')) { function php_box($s) { $code = stripslashes($s[1]); $break = ' '; if(strpos($code,'<?php')===false) $code = '<?php '.$break.$code.$break.'?>'; return printCode( html_entity_decode($code), true, 'PHP: '); } } $text = preg_replace_callback('/\[php\](.*?)\[\/php\]/Usi','php_box',$text); // BBCode [ code ] if (!function_exists('escape')) { function escape($s) { return printCode( html_entity_decode($s[1]), true); } } $text = preg_replace_callback('/\[code\](.*?)\[\/code\]/msi', "escape", $text); // BBCode [ quote ] / [ quote="name" ] if(!function_exists(parseQuotesRecursive)) { function parseQuotesRecursive($input) { $regex = '#\[quote\=?"?(.*?)"?\]((?:[^[]|\[(?!/?quote\=?"?(.*?)"?\])|(?R))+)\[/quote\]#i'; if (is_array($input)) { $input = '<blockquote style="margin: 5px 20px 20px;">' .'<div style="margin-bottom: 2px;font-size:10px;font-family:sans-serif">' .'Quote'.( (strlen($input[1])>0) ? ' From <strong>'.$input[1].'</strong>' : '' ).',' .'</div>' .'<div style="padding:4px;padding-top:0;border:#000 1px inset">' .$input[2] .'</div>' .'</blockquote>'; } return preg_replace_callback($regex, 'parseQuotesRecursive', $input); } } $text = parseQuotesRecursive($text); //BBcode to Find.. $in = array( '/\[b\](.*?)\[\/b\]/si', '/\[i\](.*?)\[\/i\]/si', '/\[u\](.*?)\[\/u\]/si', '#\[img\](https?://[-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|]\.(?:jpg|jpeg|gif|png|bmp))\[\/img\]#si', '#\[email\]([-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|])\[\/email\]#si', '#\[url\=((?:ftp|http?)://[-A-Z0-9+&@\#/%?=~_|!:,.;]*[-A-Z0-9+&@\#/%=~_|])\](.*?)\[\/url\]#si', '/\[size\="?(.*?)"?\](.*?)\[\/size\]/si', '/\[color\="?(.*?)"?\](.*?)\[\/color\]/si', '#\[url\]((??!/?\[(?:url|b|img|i)\]).)*?)\|(.*?)\[/url\]#si', '#\[url\]((??!/?\[(?:url|b|img|i)\]).)*?)\[/url\]#si', '/\[list\=(.*?)\](.*?)\[\/list\]/si', '/\[list\](.*?)\[\/list\]/si', '/\[\*\]\s?(.*?)\n/si' ); // And replace them by... $out = array( '<strong>\1</strong>', '<em>\1</em>', '<u>\1</u>', '<img src="\1" alt="\1" />', '<a href="mailto:\1">\1</a>', '<a href="\1">\2</a>', '<span style="font-size:\1%">\2</span>', '<span style="color:\1">\2</span>', "<a href='$1'>$2</a>", "<a href='$1'>$1</a>", '<ol start="\1">\2</ol>', '<ul>\1</ul>', '<li>\1</li>' ); $text = preg_replace($in, $out, $text); // paragraphs $text = str_replace("\r", "", $text); $text = "<p>".ereg_replace("(\n){2,}", "</p><p>", $text)."</p>"; $text = nl2br($text); // clean some tags to remain strict // not very elegant, but it works. if (!function_exists('removeBr')) { function removeBr($s) { return str_replace("<br />", "", $s[0]); } } $text = preg_replace_callback('/<pre>(.*?)<\/pre>/ms', "removeBr", $text); $text = preg_replace('/<p><pre>(.*?)<\/pre><\/p>/ms', "<pre>\\1</pre>", $text); $text = preg_replace_callback('/<ul>(.*?)<\/ul>/ms', "removeBr", $text); $text = preg_replace('/<p><ul>(.*?)<\/ul><\/p>/ms', "<ul>\\1</ul>", $text); return $text; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247651-bbcode-making-the-tag-inactive/ Share on other sites More sharing options...
php_begins Posted September 22, 2011 Author Share Posted September 22, 2011 If i remove the BBCodeToHTML function it works..but I need the BBCODE parser for other things too. Quote Link to comment https://forums.phpfreaks.com/topic/247651-bbcode-making-the-tag-inactive/#findComment-1271752 Share on other sites More sharing options...
DavidAM Posted September 22, 2011 Share Posted September 22, 2011 function BBCodeToHTML($text) { $text = trim(htmlentities($text)); The first line of your BBCode function is converting all HTML to HTML Entities; which is proper. So the <IMG > tag is changed to be displayed rather than interpreted. You should probably be using the BBCode tag for an image ( . Quote Link to comment https://forums.phpfreaks.com/topic/247651-bbcode-making-the-tag-inactive/#findComment-1271780 Share on other sites More sharing options...
php_begins Posted September 22, 2011 Author Share Posted September 22, 2011 Thank you.. that was the problem.. Quote Link to comment https://forums.phpfreaks.com/topic/247651-bbcode-making-the-tag-inactive/#findComment-1271827 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.