Jump to content

bbcode problems


Noskiw

Recommended Posts

<?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

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

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

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

<?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

<?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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.