Im making a new bbcodes for my site this is what i have so far
| Code: |
<?php
function UnHtml($string)
{
return strtr($string, array_flip(get_html_translation_table()));
}
function bbcode($content){
$content = nl2br(stripslashes($content));
$content = str_replace ("[b]", "<b>", $content);
$content = str_replace ("[/b]", "</b>", $content);
$content = str_replace ("[php]", " <fieldset style='width: 450'><table width='100%' cellpadding='0' cellspacing='0' style='border-bottom:1px solid #000000;'><tr><td><b>PHP:</b></td></tr></table>", highlight_string(UnHtml($content)));
$content = str_replace ("[/php]", "</fieldset>", $content);
return $content;
}
?> |
Im trying to add a highlight_string to my [php] bbcode but for this i have to undo the htmlspechar thing, so my friend gave the the UnHtml function. But this is undoing all of the htmlspec....
Please could you help
Thanks DanielXP
Last edited by DanielXP on Thu Dec 28, 2006 9:08 pm; edited 1 time in total
could you do this with a preg_replace?
if so could you give me the line code for it
Why do you need to undo htmlspechar? and I don't find htmlspechar in your code. Where have you used it?
Instead of undo, can you try highlight_string before htmlspechar and have rest of conversions after htmlspechar?
Before the code enters into my database it htmlspechar it.
So before i highlight it, it needs to be in html form.
BB code is a bit more complex than that - you need to make sure every opening tag has a closing tag, or else people can reak havoc with the site's look on a page with their BB code.
| Agent ME wrote: |
| BB code is a bit more complex than that - you need to make sure every opening tag has a closing tag, or else people can reak havoc with the site's look on a page with their BB code. |
U what?
Ok as this is taking a long time
150 FRIH$ for the person who can give me the code what works on my site.
Thanks
Daniel
Bump
Please i really need this
my site is waiting 2 be released
It looks to me you have to put the UnHtml before the other conversion functions, because it reverts the changes made with the str_replace-calls:
| Code: |
<?php
function UnHtml($string)
{
return strtr($string, array_flip(get_html_translation_table()));
}
function bbcode($content){
$content = UnHtml($content) // <-- changed
$content = nl2br(stripslashes($content));
$content = str_replace ("[b]", "<b>", $content);
$content = str_replace ("[/b]", "</b>", $content);
$content = str_replace ("[php]", " <fieldset style='width: 450'><table width='100%' cellpadding='0' cellspacing='0' style='border-bottom:1px solid #000000;'><tr><td><b>PHP:</b></td></tr></table>", highlight_string($content); // <-- changed
$content = str_replace ("[/php]", "</fieldset>", $content);
return $content;
}
?>
|
| MrBlueSky wrote: |
It looks to me you have to put the UnHtml before the other conversion functions, because it reverts the changes made with the str_replace-calls:
| Code: |
<?php
function UnHtml($string)
{
return strtr($string, array_flip(get_html_translation_table()));
}
function bbcode($content){
$content = UnHtml($content) // <-- changed
$content = nl2br(stripslashes($content));
$content = str_replace ("[b]", "<b>", $content);
$content = str_replace ("[/b]", "</b>", $content);
$content = str_replace ("[php]", " <fieldset style='width: 450'><table width='100%' cellpadding='0' cellspacing='0' style='border-bottom:1px solid #000000;'><tr><td><b>PHP:</b></td></tr></table>", highlight_string($content); // <-- changed
$content = str_replace ("[/php]", "</fieldset>", $content);
return $content;
}
?>
|
|
Im getting this error
| Code: |
| Parse error: syntax error, unexpected T_VARIABLE in /home/____/public_html/___/bbcodes.php on line 9 |
I'm sorry, i made two mistakes: I forgot a ')' and a semicolon:
| Code: |
<?php
function UnHtml($string)
{
return strtr($string, array_flip(get_html_translation_table()));
}
function bbcode($content){
$content = UnHtml($content); // <-- semi-collon added
$content = nl2br(stripslashes($content));
$content = str_replace ("[b]", "<b>", $content);
$content = str_replace ("[/b]", "</b>", $content);
$content = str_replace ("[php]", " <fieldset style='width: 450'><table width='100%' cellpadding='0' cellspacing='0' style='border-bottom:1px solid #000000;'><tr><td><b>PHP:</b></td></tr></table>", highlight_string($content)); // <-- closing parenthize added
$content = str_replace ("[/php]", "</fieldset>", $content);
return $content;
}
?>
|
Just notice that would undo all the html so theres no point doing the htmlspecialcahrs in the fisrt place
Correct?
If your running a tutorials site theres loads of HTML scripts they will be posting, so if i used this then that would just inport the html into the page and not display it