Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2011
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <?php
  2. function AddBBCodes($hayStack)
  3. {
  4. $bbcodeArray=array(
  5. 'b'=>array('open_tag'=>'[b]', 'close_tag'=>'[/b]', 'open_html'=>'<b>', 'close_html'=>'</b>'),
  6. 'u'=>array('open_tag'=>'[u]', 'close_tag'=>'[/u]', 'open_html'=>'<u>', 'close_html'=>'</u>'),
  7. 'i'=>array('open_tag'=>'[i]', 'close_tag'=>'[/i]', 'open_html'=>'<i>', 'close_html'=>'</i>')
  8. //add more bbcodes you want here, these are just basic ones
  9. );
  10. $results=$hayStack;
  11. foreach($bbcodeArray as $child)
  12. {
  13. $hayStack=" $results ";
  14. 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
  15. {
  16. $hayStack=str_ireplace($child["open_tag"], $child["open_html"], $hayStack, &$startTagNo);
  17. $hayStack=str_ireplace($child["close_tag"], $child["close_html"], $hayStack, &$closeTagNo);
  18. if($startTagNo == $closeTagNo) $results=$hayStack;
  19. }
  20. }
  21. return $results;
  22. }
  23. echo AddBBCodes("Put any string here.");
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement