Advertisement
fabi0

Untitled

Jun 16th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  * Description of BBCode
  11.  *
  12.  * @author fabi0
  13.  */
  14.  
  15. namespace Models;
  16.  
  17. class Bb {
  18.  
  19.     private static $_search = array(
  20.         '~\[hr\]~s',
  21.         '~\[b\](.*?)\[/b\]~s',
  22.         '~\[i\](.*?)\[/i\]~s',
  23.         '~\[u\](.*?)\[/u\]~s',
  24.         '~\[quote\](.*?)\[/quote\]~s',
  25.         '~\[size=(.*?)\](.*?)\[/size\]~s',
  26.         '~\[color=(.*?)\](.*?)\[/color\]~s',
  27.         '~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
  28.         '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s',
  29.         '~\[p\](.*?)\[/p\]~s'
  30.     );
  31.     private static $_replace = array(
  32.         '<hr/>',
  33.         '<b>$1</b>',
  34.         '<i>$1</i>',
  35.         '<span style="text-decoration:underline;">$1</span>',
  36.         '<pre>$1</pre>',
  37.         '<span style="font-size:$1px;">$2</span>',
  38.         '<span style="color:$1;">$2</span>',
  39.         '<a href="$1">$1</a>',
  40.         '<img src="$1" alt="" />',
  41.         '<p>$1</p>'
  42.     );
  43.  
  44.     public static function parse($code) {
  45.         return preg_replace(self::$_search, self::$_replace, $code);
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement