Bbcode Help
This is my first time doing bbcode so I'm not really sure how to do this. I copied this from a tutorial but it doesn't work.
$string = "I am so [b]cool[/b] ";
$bb-replace = array('[b]','[/b]','[i]',[/i]');
$bb-replacements = array ('<b>','</b>','</i>','</i>');
$string = str_replace($bb-replace,$bb-replacements,$string);
The error is a syntax error unexpected T_ARRAY.
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
BbCode Into
Can anyone recommend a simple way of implementing bbcode into a php-based website/database design? I'd like the user to be able to enter the data using bbcode's options (simple click and format options without having to know anything about code... like this site has) and have this display in pages when the results are pulled out of the database and displayed in HTML format.
View Replies !
View Related
Implementing BBCODE?
I have been working on a system to add news and articles to a site, I have the core adding and removing out of the way and have had some very good advice from eelixduppy, the code for what i currently have is at the end of this post. What i would to acheive is something where if i typed: HELLO and wanted to make it bold i could wrap HELLO in something like the BBCODE on this forum. for example square brackets with a B inside to start the Bold area and square brackets with a /B inside to close the bold area, I would like to know how i can underline things with this too and perhaps add things such as font colours etc. a basic intro into how to get it to work would be great, here is the code i currently have if it helps in anyway at all. <?php include 'dbconnect.php' $title = $_POST['title']; $news = $_POST['news']; $pattern = "/(http://[w.]+)/"; $replace = "<a href='$1'>$1</a>"; $title = preg_replace($pattern, $replace, $title); $news = preg_replace($pattern, $replace, $news); $title = mysql_real_escape_string($title); $news = mysql_real_escape_string(nl2br($news)); $date = date("D d M Y, g:i a"); $sqlquery = "INSERT INTO tnews (Title, Body, Date) VALUES ('$title','$news','$date')"; header("Location: display.php"); //print $sqlquery; $results = mysql_query($sqlquery); mysql_close($dbc); ?>
View Replies !
View Related
Help With My Bbcode Function
Someone here very kindly gave me a small example of how to implement a bbcode function, I have expanded this function so it now looks like this. bbcode.php <? function bb2html($text) { $trans = array("" => '<b>', "" => '</b>', "[u]" => '<u>', "[/u]" => '</u>', "" => '<i>', "" => '</i>', ":-)" => '<img src="../images/smile.gif" title="smile :-)">', ";-)" => '<img src="../images/wink.gif" title="wink ;-)">', "->" => '<img src="../images/arrow.gif" title="arrow">', ">-)" => '<img src="../images/badfrin.gif" title="bad grin">', ":-D" => '<img src="../images/biggrin.gif" title="big grin">', ":-S" => '<img src="../images/confused.gif" title="confused">', "0-)" => '<img src="../images/cool.gif" title="cool">', ";-(" => '<img src="../images/cry.gif" title="cry">', "/-¦" => '<img src="../images/doubt.gif" title="doubt">', ":-@" => '<img src="../images/evil.gif" title="evil">', "<!>" => '<img src="../images/exclaim.gif" title="exlamation">', "<i>" => '<img src="../images/idea.gif" title="idea">', "<lol>" => '<img src="../images/arrow.gif" title="lol">', ">-<" => '<img src="../images/mad.gif" title="mad">', ":-¦" => '<img src="../images/neutral.gif" title="nuetral">', "<?>" => '<img src="../images/question.gif" title="question">', ":-P" => '<img src="../images/raz.gif" title="raz">', "$-¦" => '<img src="../images/redface.gif" title="red face">', "8-¦" => '<img src="../images/rolleys.gif" title="rolly eyes">', ":-(" => '<img src="../images/sad.gif" title="sad">', ">-O" => '<img src="../images/shock.gif" title="shock">', ":-O" => '<img src="../images/suprised.gif" title="suprised">', " " => '<table bgcolor='#cccccc'><tr><td style='border: solid 1px #000000'>', " " => '</td></tr></table>'); $translated = strtr($text, $trans); return $translated; } ?> I do however have a small problem this works fine first time when I add the data to the database, I am using the following code to add the data to the database newsadd.php <?php include '/home/www/juttuffi/auth.php' include '/home/www/juttuffi/dbc.php' include '/home/www/juttuffi/news/admin/bbcode.php' $pattern = "/(http://[w.]+)/"; $replace = "<a href='$1'>$1</a>"; $title = $_POST['title']; $news = $_POST['news']; if (!empty($title) &&!empty($news)) { $title = preg_replace($pattern, $replace, $title); $news = preg_replace($pattern, $replace, $news); $title = bb2html($title); $news = bb2html($news); $title = mysql_real_escape_string($title); $news = mysql_real_escape_string(nl2br($news)); $date = date("D d M Y, g:i a"); $sqlquery = "INSERT INTO tnews (title, body, date) VALUES ('$title','$news','$date')"; header("Location: index.php"); //print $sqlquery; $results = mysql_query($sqlquery); } else { include '/home/www/juttuffi/header.php' echo '<san class="notice">' echo '***ERROR: Please make sure you have entered a title and some news***' echo '</span>' echo '<br>' include '/home/www/juttuffi/news/admin/newsaddform.php' } mysql_close($dbc); ?> This works fine the smilies appear fine in the output, however when i use my edit script which is below i get some distorted output, here is my edit script. newsedit.php <?php include '/home/www/juttuffi/auth.php' include '/home/www/juttuffi/dbc.php' include '/home/www/juttuffi/news/admin/bbcode.php' $pattern = "/(http://[w.]+)/"; $replace = "<a href='$1'>$1</a>"; $title = $_POST['title']; $news = $_POST['news']; $id = (int)$_POST["id"]; if (!empty($title) &&!empty($news)) { $title = preg_replace($pattern, $replace, $title); $news = preg_replace($pattern, $replace, $news); $title = bb2html($title); $news = bb2html($news); $title = mysql_real_escape_string($title); $news = mysql_real_escape_string(nl2br($news)); $sqlquery = "UPDATE tnews SET title='$title', body='$news' WHERE id='$id'"; header("Location: index.php"); //print $sqlquery; $results = mysql_query($sqlquery); } else { include '/home/www/juttuffi/header.php' echo '<span class="notice">' echo '***ERROR: Please make sure that yu have not tried to submit any empty fields***' echo '</span>' echo '<br>' include '/home/www/juttuffi/news/admin/newseditform.php' } mysql_close($dbc); ?> as you can see the edit code is almost identical to the add code, however say i added a simple news post which contained one smiley. :-), this would appear as a smiley fine but then say i edited the post and didn't change anything but just clicked "edit" you would expect there to be no change in the output and for it to remain a smiley :-) instead i get something like this after editing :-)"> can anyone help me locate the problem here and perhaps tell me how to solve it, I would be extremely grateful.
View Replies !
View Related
Strip Bbcode
I've been trying to piece together a function that can strip bbcode/vBcode from a block of text (ie: posts). I don't want to translate any of it - just remove all instances of [ ] and whatever tags are between them. This is probably a simple string parsing application, but I can't seem to figure out a way to pull it off.
View Replies !
View Related
Bbcode Interface
I'm implementing a bbcode parsing engine on a news script, but my only concern is how to create those buttons that interact with the textbox and automatically insert tags and such when you click on them.
View Replies !
View Related
Parsing (BBCode)
I'm trying to make a BBCode parser for a forum project I'm working on. I've got the whole bit that finds the code and says turn [b] -> <strong> and that, but my problem is, if you put [b]text, the rest of the page is in bold. What I want is it to automatically add the closing tag. How do I do this?
View Replies !
View Related
Youtube BBcode
i want to add a youtube bbcode to my online game to allow players to embed youtube into their profiles using [youtube]video id[/youtube] so i need to convert this to work as the above bbcode <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/YEfKdjOjqso"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/YEfKdjOjqso" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object> thats just a example embed. ive tried several different ways of doing this, any ideas?
View Replies !
View Related
Bbcode Code
static function code($string) { return preg_replace("/[code](.*?)[/code]/", "<div id='code'>$1</div>", $string); } When i type: [code] <br /> <?php echo 'Hello world'; ?> <br /> [/code] It doesnt recognize the code-brackets, why not?
View Replies !
View Related
Bbcode For Quote
On my forums I am trying to add a quotes user feature so that it will parse this to the page when bbcode is used like this. PHP Code: [quote=username] text here [/quote] will output this. Code: <div class="Quote_User" style="margin-bottom: 5px;"> <b><a href="?p=profile&userid=1">USERNAME</a> wrote:</b> <br> <div style="padding-top: 5px;"></div><i>TEXT HERE</i></div>
View Replies !
View Related
BBCode Stripping
I want to disable BBCode feature in my forum. But I want to leave [quote ] [ /quote] tags for quotations purposes... I have messages stripped from BBCode before saving to database by this function: Code:
View Replies !
View Related
Strippping BBCode!
I need some help on replacing 'nested' BBCode, preferably using preg_replace. Say I have a text like: [quot:5e946ce841="user1"]:-)[quot:5e946ce841="user2"]Hi, there! [/quot:5e946ce841] Hey, Howdy!! [/quot:5e946ce841] bla bla bla... I want it converted to: <quot>:-)<quot>Hi, there! </quot> Hey, Howdy!! </quot> bla bla bla... converting '[quot]' into '<quot>' & '[/quot]' into '</quot>'
View Replies !
View Related
FCKeditor Vs BBcode
I need some forms that would let the user format the text just a little. The format that I'm letting the user to use is bold, italic, font size, links and some alignments. I'm trying FCKeditor, but it's too robust for what I want (alghough it can be well customized). I'm wondering if there's any other nice utility even if it's more basic, but that can suit my needs? Also, what's more secure to use? a FCKeditor that handles html tags directly or BBcode?
View Replies !
View Related
Irregular Bbcode
I Have regexp replacements in order to have working bbcode on the site. But I also want to include new tag which will remove any codes inside of itself (ie write them as text). It's easy in theory - just to grab everything inside NO tag and replace all "[" and "]" to their html codes (ie [ and ]). It doesn't have to be a regexp, i can do replacement b4 everything else, cuz regexp may actually slow down performance in this case.
View Replies !
View Related
Emoticons And Bbcode
I'd like enable visitors to my website to use bbcode and emoticons whilst entering text into a form. Are there any standard lumps of php/javascript I can use for this purpose?. In particular the encoder/decoder for the emoticons & bbcode and any examples of form layouts for textual input with all the appropriate '[url]' and emoticon buttons.
View Replies !
View Related
BBcode Parser
im making a website, its not a forum or anything like that but it does require the user of BBcode. i decided to use this because allowing the users to use html (like how myspace did) creates too many security risks and i like my design how it is so i am going to keep it. i want to know how i can implement BBcode on my page. i need all the basic functions. does anyone have any areas of expertise here. ive looked at multiple tutorials but i get lost in them all . does anyone have a link to a good on.
View Replies !
View Related
Displaying Bbcode
Currently I've been working on a news script for my website and I've been pulling posts from a set forum but since they are displaying in plaintext I was wondering how I would go about displaying the bbcode tags correctly. For example, one of my posts the text is [b:0236504185]Links:[/b:0236504185]
View Replies !
View Related
Regex BBCode Code
I've got my forum system setup so you can use BBCode [url ] etc....... but if the user doesn't put [url ] a round a hyperlink i want when the message is posted to add the [url ] around it if not already there.
View Replies !
View Related
Remove Bbcode From Text
I have the following code that pulls text and subject from a phpBB database and displays it on the main page of a site. I want to pull the bbcode tags out cause it looks ugly. My question is how would I integrate that in to the code that I have below? Code:
View Replies !
View Related
Php Script That Does All The Bbcode Stuff?
if there is anywhere i can download a php script that does all the bbcode stuff for me? Because i need something like that and, though i can write the code myself if i need to, downloading the script would save ALOT of time. So no worries if there isn't anywhere i can get it. But i was just curious. I already did some searching on google myself, and i didn't seem to be able to find anything.
View Replies !
View Related
Making My Own BBCode, Sort Of..
Right heres the thing I have multiple files, tutorials.php lists the tutorials and view_tutorial.php displays the tutorial by getting the id. Anyways I need to display code in parts of the tutorial, with only part of it needing highlighting I can't use highlight_string(); How would I go about making a tag that wraps around my code, sits the same in the database then is displayed in a box with syntax highlighting? Also it needs to keep <html> tags in-tact, nother words I don't want them to vanish once its shown to the user.
View Replies !
View Related
BBCode [quote] Iteration
I have basic code for [quote=name]: '`[quote=(.+?)](.+?)[/quote]`i' However, when there is a quote within a quote, only the first [quote] is converted. What can I do to solve this without having to call preg_replace again?
View Replies !
View Related
Replacing Bbcode With Html Tags Using Php
i have a place for people to post with bbcode (written with javascript), the data is posted and sent to a mysql database, and retrieved from my website's page, where it is displayed. when the data shows up on the page, the bbcode is still visible. is there a php script for this? if there is where would i put it? on the website's page?
View Replies !
View Related
BBcode, Forms And Database Security
I have a form where the user can enter some BBcode to style text but I am really concerned about database security. When I submit a form, I use stripslashes to get rid of the crap before it enters the database but will this affect the BBcode as it has a slash i.e. [/tag] What is the best way so i can insert the BBcode or the converted HTML into my database without compromising my database?
View Replies !
View Related
Removing The Bbcode_id From Bbcode Tags
phpbb, at least, puts a unique ID number into each bbcode tag a user posts, for example, if I were to post bold text and look at the raw code in the database, it would look like this: [b:9f0e836e4c]bold text[/b:9f0e836e4c] Now, it's simple enough to remove those numbers using this regex: [b:[^]]+] What's really got me stumped, though, is how to do this when the bbcode has attributes, such as size and a quote: Code:
View Replies !
View Related
BBCode Parsers And Exporting Text From A DB
I'm currently working on a simple (at least I had hoped) script to pull posts from a single "news" forum from phpbb and importing it on the front page of my site. It works great except for the BBCode issues. It doesn't keep line breaks (biggest concern) as well as text colors, urls, etc (which was expected). Talking with a friend, he tells me that I'm going to have to insert some BBCode parser to make things work right. I have 3 questions regarding this: 1) is that my only answer? 2) should I try to use the phpbb BBCode parser that the forum uses? 3) should I install a custom BBCode parser instead? I did not want to use a portal because they were just over bloated for what I needed and that was simply the posts from the forum itself w/o all the extras like who's online, last post made on the forums, etc. Would it just be easier to try to strip down something like EZportal to just the info I need instead of trying to use this custom script?
View Replies !
View Related
BBCode To Be Converted To HTML Attributes
I'm creating a small web app in PHP/MySQL and I'm building the backend. At the moment when one of my novice users enter some news via the form it enters it as a text string into the database. However I need that string styled and as my users are experienced with BBCode I thought they might as well be able to use that. So what I need is for their BBCode to be converted to HTML attributes either when it's being added to the db or when it's being displayed. I can find plenty of scripts, but as I'm a bit of a rookie - I need some installation instructions too! Has anybody dealt with bbCode in your apps before? Does anybody have any ideas?
View Replies !
View Related
Combining BBcode To Create One Html Tag
I'm working on some BBCode and I was wondering if it is possible to combine two bbcode tags to create one span tag after the preg_replace e.g. Code: [font=Arial ][b ][color=red ]Text[/color ][ /b][/font ] HTML Code: <span style='font-family:Arial;font-weight:bold;color:red;'>Text</span> instead of HTML Code: <span style='font-family:Arial;'><span style='font-weight:bold;'><span style='color:red;'>Text</span></span></span> Of course I'd need it for multiple instances of nested BBcode tags within the same message.
View Replies !
View Related
Parsing Text Links And BBCode At The Same Time
I'm not sure if my subject for this is accurate but here is what I'm trying to do: I want to be able to parse BB sytle code along with regular text links at the same time within the same string. Here's what I mean... I have links in a string that can appear in two forms simultaneously: 1) [ url=http://www.abc.com]abc[/url] (without the space of course) 2) http://www.abc.com Both need to be converted to HTML links of the form <a href="http://www.abc.com">...</a> I can do each operation on it's own without any problems but trying to differentiate between bbcode and regular text links is giving me some trouble. I'm currently using the following code for converting links to HTML which works great for my purposes: $text = eregi_replace("((ht|f)tp://www.|www.)([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})((/|?)[a-z0-9~#%&/'_+=:?.-]*)*)", "http://www.3", $text); $text = eregi_replace("((ht|f)tp://)((([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4}))|(([0-9]{1,3}.){3}([0-9]{1,3})))((/|?)[a-z0-9~#%&'_+=:?.-]*)*)", "<a href=" |