Jul 25, 2008

Use Bb Code On Your Site! - Just like on forums!

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Use Bb Code On Your Site! - Just like on forums!

Unholy Prayer
To use this you must have PHP support on your server. Just use this code:

CODE
<?php

$content = "Hello, World!";

$html = array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]');
$replacements = array ('<b>', '</b>', '<i>', '</i>', '<u>', '</u>');

$content = str_replace($html, $replacements, $content);

?>


This code can be very useful. It can be used for word filters to block the use of bad words on your site or for emoticons.

Reply

Imtay22
So I can just create a php file called whatever.php and put that code in it?

Reply

Blessed
yes you can m8

but make sure to put it out like this

$content = str_replace($html, $replacements, $content);

Reply

galexcd
str replace is bad for bbcode especially when it comes to urls etc.

If you use preg_replace, you can get php to check to make sure it actually has an ending. That way if sombody leaves a [b] tag open, it dosn't parse it out. They would have to close it.

Here's the bb code i use on the forums i coded.

CODE
$main_search=array('/\[b\](.*?)\[\/b\]/is','/\[i\](.*?)\[\/i\]/is','/\[u\](.*?)\[\/u\]/is','/\[img\](.*?)\[\/img\]/is','/\[url\=(.*?)\](.*?)\[\/url\]/is','/\[url\](.*?)\[\/url\]/is','/\[color\=(.*?)\](.*?)\[\/color\]/is','/\[code\](.*?)\[\/code\]/is');
$main_replace=array('<strong>$1</strong>','<em>$1</em>','<u>$1</u>','<img src="$1" style="max-width: 100%" border="0">','<a href="$1">$2</a>','<a href="$1">$1</a>','<font color=$1>$2</font>','<div style="WIDTH: 100%; OVERFLOW: auto"><pre>$1</pre></div>');
$str=preg_replace ($main_search, $main_replace, $str);



Str_replace is good for smilies though!

 

 

 


Reply

Imtay22
Ok! Do they both work though? I used another tutorial here that used preg_replace. They also said it was more better than str_replace. Unholy, you might want ot take his advice!

Reply

galexcd
QUOTE(Imtay22 @ Apr 13 2007, 03:08 PM) *
Ok! Do they both work though? I used another tutorial here that used preg_replace. They also said it was more better than str_replace. Unholy, you might want ot take his advice!


More better? lol

If you use preg_replace you'll get a much more professional bb parser. It would be more like trap17's bb. This would be the effect you would get:

[b]if this board used str_replace to parse bb code, the rest of this post would be bold because the bold tag would be parsed and replaced into <b> no matter what.



Reply

Imtay22
Ahhh.... Okay. Thanks. I think I will stick with the easyer one.

Reply

galexcd
The problem with using str_replace for tags like img is you would have to have [img] replace to <img src=" and [ /img] replace to ">. Now if you think about it, if you use that, anybody could easily break your forums by just starting an image tag without ending it. If you write <img src=" in the middle of your code, it's not going to end untill it sees another quote and another greaterthan. If your site uses tables, this could really screw up the site.

P.S.
Along with emoticons, str_replace is really good for disabling HTML.

CODE
$string=str_replace(array("<",">"),array("&lt;","&gt;"),$string);

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. bbcode of talents - 76.32 hr back. (1)
  2. php bbcode decoder - 163.89 hr back. (1)
Similar Topics

Keywords : bb, code, site, forums

  1. Create Table - Mysql Code - Help
    (1)
  2. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  3. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free
    host together so am writing some posts. Here's a little summin' summin' about malicious
    code injection with PHP applications. Basically, this security exploit is one of the oldest tricks
    in the books and all comes down to the fact that PHP allows execution of both local and remote
    scripts with the SAME function... dur. Anyway, this is how it works. Image you've just employed
    a young go getter, straight outta uni, who has found becoming a Jack of all trades a ....
  4. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
    help guys...I want to make a simple program that will some values and then store them on a database
    and then retrieve them...uhmm let me give an example out put of what i need. This is the example
    say..: Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those
    are the data needed for input values...my question now is how can I make a database....
  5. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is
    above this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  6. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  7. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  8. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  9. Use Rss In Php Code
    (3)
    so, how can I make RSS reader on my website? thanks in advance....
  10. Xbox Gamertag Profile On Site
    (2)
    Alright, first off, sorry about the title, can't exactly explain it well. Basically, I want to
    have it so; 1. My users sign up on my website (easy enough, don't need help with) Now, this
    part might get confusing, but I need major help, as I see no way of doing it, yet I would love for
    it to happen. When they post on my website (comment), (this part I don't need help with), I
    wish for their gamer profile to show up under their name, so It'll say; Nate posted on (date):
    (gamer profile here) blah blah blah the trouble is, I have no idea how to get the ....
  11. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE <?php $p =
    $_GET['p']; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.'
    ) == False ) { // pages = directory where you store your pages    $file = './'
    . $p . '....
  12. I Need Some Proof Reading For My Code Please! [resolved]
    (7)
    Well... everything is fine except the Content Select section (refer to the in-code headings)...
    thats where it says the error is... could anyone find out why it wont work when I click one of my
    links? http://2kart.trap17.com/progress.php for an example of what happens...
    //----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay
    = "/images"; //------------------ //navigation //------------------ $link = ·   Home
    html; $link = ·   Portfolio html; $link = ·   Programming html; $link = ....
  13. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE <?php //Save this as something like htmltest.php function
    CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
    input $html_safe=str_replace("<?php"," ",$html_unsafe);
    //Starts security measures $html_safe=str_replace("?>","
    ",$html_sa....
  14. Awesome Source Code Viewer Script
    (7)
    Hello! I have just came up with a sweet script to show the source code of any website and it
    only requires one file. This is the basis of the script and can be customized with CSS and other
    things and can be instituted as a public resource. Well I will provide the code and a step-by-step
    tutorial on each of its parts. This code has been tested by me. Enjoy! CODE <?php
    //This little tag starts our php script and is easily the most important part of the script. //We
    will start our base script here. //You can change some of the styles used here to your des....
  15. Html Site With Login
    Is it possible? (2)
    Hello. I´m building my own site and I need some help... Is it possible to use a login sistem in php
    and mysql database in a html site? ....
  16. Connecting Php Site To Database
    (6)
    Please Help Me with this site's error http://gatewaybiz.x10hosting.com/surf/ ....
  17. Whats Wrong>?
    please see this piece of code and see whats wrong: (9)
    CODE require('connection2.php'); $select=mysql_query("SELECT * from
    `users` WHERE password='$_GET[password]'");
    $co=mysql_num_rows($select); if ($co = 1) {
    session_start(); $s=session_id();
    $_SESSION['access']="yes";
    $username=$_GET['username'];
    header("location:../main/index2.php?a=$_GET[username]&s=$s"
    ;); //echo "<a href='.&....
  18. Displaying Your Phone Number On A Wap Site
    (3)
    I have a wap site elitezone.co.za and what i want to add is a code to the index page that displays
    your operator and phone number. Does any one know the coding for this function if so please show me
    here. Help will appriacated. Topic title modified. ....
  19. How To Make A Random 7 Number Code?
    (2)
    I am making a script in php, and for it I need to know how to make a random 7 digit code. I think it
    has something to do with md5, but i am not sure. Thanks! EDIT- Can someone please change the
    title to "How to make a random 7 digit code in php?" Thanks!....
  20. Php Education Class (first Code)
    (0)
    Hi I want to educate some PHP codes that i think they will be useful for all of you! My 1st
    code is this: CODE <?php class calculator {          /**      * Variable for holding all
    the numbers to add      *      * @var array      */     private $numbers = array();
             /**      * Variable holding all the digits after the point      *      * @var array      */
        private $afterPoint = array();          /**      * Maximum number of digits after
    the point      * that a number has      *      * @var int      */     private $....
  21. New Arisen Site Problem
    Nettek Login Trouble (2)
    Okay, so I installed Nettek and got everything set up. But every time I try and login, it says
    it's incorrect. I've gone into the Database and gotten the password and since it was
    simple, put them in and had tried but with no success. I tried changing the password but I still
    couldn't get in. I tried adding another login and it still didn't work. I have no idea
    what's wrong and I need some help.....
  22. Php Problems
    Clan Web site Problem (3)
    Okay, so I have an old version of Nettek that I would like to modify. There is a bug that when you
    get to the rank required for Set Rank, you can set your rank or other people's ranks to what
    ever you want, even Webmaster and that's something I'd like to not have. I am wondering how
    to fix the problem. What would I modify in the coding to set have it so you can only move people up
    to 1 rank below you at best? I'm still learning PHP and can't modify things like this quite
    yet.....
  23. My Code Doesnt Resize Large Images, Please Help.
    (2)
    Can someone please have a look at the following code, this uploads an image, and make it in 2 sizes,
    one size is max. 600 x 800, uploads to images folder and second 120 x 120 and uploads to thumbs
    folder. this script works fine, with normal size images, but if i try to upload large pics( for
    example, an image with dimension 2432 x 3300, it shows blank page, and uploads the original image
    without sizing to "image" folder, and doesnt make any small thumbnail... I hope u understand..
    Please someone help me, i shall be so thankful. session_start(); header("Cache-contro....
  24. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE <? header("Content-Type:
    text/vnd.wap.wml"); echo '<?xml version="1.0"
    encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head><meta
    http-equiv="Cache-Control" content="no-cache"
    forua="true"/></head> <card title="s60.nerds.....
  25. Dynamic Image / Signature Generator
    a simple code to change text on an image (12)
    In search of dynamically changing quote, saying or all other types of text on an image I came across
    a code that I have modified to fit my initial usage. This procedure requires two files and short
    knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
    procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
    at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
    CODE <?php header("Content-type: image/png"); �....
  26. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved
    to Programming. ....
  27. Wap Forum
    several questions on WAP forums (9)
    /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /> Right i want to set up a
    wap forum for rap battling. I think i need to use php, although i might need wml not sure. so
    questions: 1) WML or PHP? 2) Can i get a forum/message board script? 3) Where can i get it? Thanks
    in advance Not making helpful thread topics and titles results in warnings, or in extreme cases, a
    ban. Don't fall into the crack. ....
  28. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  29. Php Clock
    source Code (7)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE <? // Binary Clock //
    script copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    [url=http://www.psychodad.at/clock/]http://www.psychodad.at/clock/[/url] //
    free to use, copy and modify but leave comments untouched;) // just include this file where
    your binary clock should appear // version 1.2   03 September 2003 // below you can ....
  30. How do you test your php code
    (75)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for bb, code, site, forums

Searching Video's for bb, code, site, forums
advertisement



Use Bb Code On Your Site! - Just like on forums!



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE