Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function AddBBCodes($hayStack)
- {
- $bbcodeArray=array(
- 'b'=>array('open_tag'=>'[b]', 'close_tag'=>'[/b]', 'open_html'=>'<b>', 'close_html'=>'</b>'),
- 'u'=>array('open_tag'=>'[u]', 'close_tag'=>'[/u]', 'open_html'=>'<u>', 'close_html'=>'</u>'),
- 'i'=>array('open_tag'=>'[i]', 'close_tag'=>'[/i]', 'open_html'=>'<i>', 'close_html'=>'</i>')
- //add more bbcodes you want here, these are just basic ones
- );
- $results=$hayStack;
- foreach($bbcodeArray as $child)
- {
- $hayStack=" $results ";
- if((stripos(strtolower($hayStack), $child["open_tag"]) != false) && (stripos(strtolower($hayStack), $child["close_tag"]) != false))//checks to see if there is the same amount of each tag, to prevent html errors
- {
- $hayStack=str_ireplace($child["open_tag"], $child["open_html"], $hayStack, &$startTagNo);
- $hayStack=str_ireplace($child["close_tag"], $child["close_html"], $hayStack, &$closeTagNo);
- if($startTagNo == $closeTagNo) $results=$hayStack;
- }
- }
- return $results;
- }
- echo AddBBCodes("Put any string here.");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement