Hi,
I have a textbox within a form, that contains the following:
[ b ]This is bold text[ /b ]
Upon submitting the form, how do I convert the [ b ] tags into <b></b> tags, to display all the text bold? - Like below?
This is bold text
Something like:
function BBCode($text){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>"); $parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $text); return $parsedtext; } $text = "[b]This is bold text[/b]
http://www.shadow-fox.net/tutorial/Building-a-BBCode-Function http://www.google.co.uk/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-GB%3Aofficial&hs=gyL&q=bbcode+function+php&btnG=Search&meta=
How would I retrieve the data from a textbox. e.g. "This text is bold"
Dysan wrote:How would I retrieve the data from a textbox. e.g. "This text is bold"
For example:
If your text box was called "txtComment" you would use the following code:
$boldText = BBCode($_POST['txtComment']); echo $boldText;
Hope this helps. Chris.
PEAR HTML_BBCodeParser package or PECL BBCode extension could be used.