Simple BBcode part 1
In this tutorial i will show you how to make a simple BBcode function for smilies.
What we want to do is to replace all the ":)" with "<img src='smile'>".
In this text we have 2 smilies: :) and :D when we are done with our script these will be replaced by <img> tags. So lets start with setting up a function:
Not much to say about that so let's go on to the next step.
Were going to store all the smiley code and html code inside 1 array called $smilies.
The $smilies array will have 2 arrays inside it. 1 for smilie codes and 1 for the html codes:
The $smilies structure will now look like this:
Note that :) is number 0 and is also 0 and so on... This is very important for this to work properly.
Now, lets move on to the next step:
What we have to do now, is to prase through the text and replace all the smiley codes with the html codes.
We use str_replace() wich replaces all the $smilies['plaintext'] with $smilies['htmltext'] from $text.
"return $text;" simply returns the finished output.
And thats it!
If you want to test it you can try this:
Wich will output:
If you got any questions or comments, please post it in the forum or use the contact page to contact me :)
Want to get in touch? Got some feedback for me? or a couple of requests? Follow me at twitter: