Using str_replace to make BB Code
by Tyler Hopfnerhttp://www.phphat.net
Thursday, 28th July 2005
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>
?>
$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.
Options:
Printer Friendly
About The Author:
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.
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.
