|
Using str_replace to make BB Code
|
|
Home Page :: Authors Login :: Author Signup :: Search :: More Articles
Home :: PHP/MySQL
|
Using str_replace to make BB Code
By Tyler Hopfner
x4n7hr4x@hotmail.com Contact Tyler Hopfner
This is a pretty simple one, you just make a couple arrays with the stuff that you want to be your BB Code, then one that will be the replacements of the BB Code, like this:
<?php
$text="www.tylerhopfner.com";
$bb=array(","" target="_blank">","");
$re=array("<a href=\"","\">link</a>");
?>
You get the point of that, you can add different tags and replacements if you want, the above is just a small example.
Now all you need to do is use the PHP str_replace() function to make the replacement:
<?php
$text="www.tylerhopfner.com";
$bb=array(","" target="_blank">","");
$re=array("<a href=\"","\">link</a>");
$final=str_replace($bb,$re,$text); // will output <a href="www.tylerhopfner.com">link</a>
?>
Thats all there is to making your own BB Code.
Discuss this in our Webmaster Forums
About The Author:
Tyler Hopfner
Tyler is a fourteen year old guy in grade 9. He have been programming and designing for 2 years now. He is very good at PHP & MySQL, and Photoshop.
|
|
|
Advertising
|
|
Advertise your website here. View Advertising Information.
|