Ok. so, finally, after hours of swimming through Kirupa’s .js files, I already have my Javascript to enter the [-b] [-/b] tags. So, when they click on a B button, it automatically enters the tags.
Now, when I bring it from the database to be displayed in the PHP file. I see the [-b] tags, like:
[-b] hey! im supposed to be bolded, but i have this B’s instead [-b]
So, how to I make BBcode work?
Please forgive my ignorance. All I have learned it’s through online tutorials, reading books, or through you guys.
I have been reading the preg_replace and the eregi_replace functions in the PHP.net site. Have been trying some, but can’t get it. Can someone help me replace all the:
sorry. i did had the [-b], thats why the text its bold. sorry
I have this form, and people could enter all kinds of formating in it: like lists, bold, change font, change font size, and i’ll have to do one replace of each.
is there a way i can simplify this? or like put the whole replace script in a file and then called it from the page?:puzzle:
*Originally posted by imagined *
**sorry. i did had the [-b], thats why the text its bold. sorry
I have this form, and people could enter all kinds of formating in it: like lists, bold, change font, change font size, and i’ll have to do one replace of each.
is there a way i can simplify this? or like put the whole replace script in a file and then called it from the page?:puzzle: **
I’m on a Regular Expression based solution which is more complex but should work better
EDIT:
<?php
$vbcode = array("b"=>"strong", "u"=>"span style=\"text-decoration:underline;\"");
function toVBCode($string, $vbcode){
foreach($vbcode as $key => $value){
$string = preg_replace("#\\[$key\\](.*)\\[/$key\\]#", "<$value>\\\\1</$value>", $string);
}
return $string;
}
$test = "**this is a test**, of [u]regexp[/u]";
$test = toVBCode($test, $vbcode);
?>
There you go just put that in a file, change $vbcode, include it, and then call toVBCode($yourstring, $vbcode). Easy as pie