Back to Opencart

File system\helper\bbcode.php

docs/api/source-system.helper.bbcode.html

4.1.0.35.2 KB
Original Source

Namespaces

Functions

| 1: | <?php | | 2: | // BBCode Converter that converts BBCode written for OpenCart | | 3: | function oc_bbcode_decode(string $string): string { | | 4: | $pattern = []; | | 5: | $replace = []; | | 6: | | | 7: | // Bold | | 8: | $pattern[0] = '/[b](.*?)[/b]/is'; | | 9: | $replace[0] = '<strong>$1</strong>'; | | 10: | | | 11: | // Italic | | 12: | $pattern[1] = '/[i](.*?)[/i]/is'; | | 13: | $replace[1] = '<em>$1</em>'; | | 14: | | | 15: | // Underlined | | 16: | $pattern[2] = '/[u](.*?)[/u]/is'; | | 17: | $replace[2] = '<u>$1</u>'; | | 18: | | | 19: | // Quote | | 20: | $pattern[3] = '/[quote](.*?)[/quote]/is'; | | 21: | $replace[3] = '<blockquote>$1</blockquote>'; | | 22: | | | 23: | // Code | | 24: | $pattern[4] = '/[code](.*?)[/code]/is'; | | 25: | $replace[4] = '<code>$1</code>'; | | 26: | | | 27: | // Strikethrough | | 28: | $pattern[16] = '/[s](.*?)[/s]/is'; | | 29: | $replace[16] = '<s>$1</s>'; | | 30: | | | 31: | // List Item | | 32: | $pattern[7] = '/[*]([\w\W]+?)\n?(?=(?:(?:[*])|(?:[/list])))/'; | | 33: | $replace[7] = '<li>$1</li>'; | | 34: | | | 35: | // List | | 36: | $pattern[5] = '/[list](.*?)[/list]/is'; | | 37: | $replace[5] = '<ul>$1</ul>'; | | 38: | | | 39: | // Ordered List | | 40: | $pattern[6] = '/[list=(1|A|a|I|i)](.*?)[/list]/is'; | | 41: | $replace[6] = '<ol type="$1">$2</ol>'; | | 42: | | | 43: | // Image | | 44: | $pattern[8] = '/[img](.*?)[/img]/is'; | | 45: | $replace[8] = ''; | | 46: | | | 47: | // URL | | 48: | $pattern[9] = '/[url](.*?)[/url]/is'; | | 49: | $replace[9] = '<a href="$1" rel="nofollow" target="_blank">$1</a>'; | | 50: | | | 51: | // URL (named) | | 52: | $pattern[10] = '/[url=([^[]+?)](.*?)[/url]/is'; | | 53: | $replace[10] = '<a href="$1" rel="nofollow" target="_blank">$2</a>'; | | 54: | | | 55: | // Font Size | | 56: | $pattern[11] = '/[size=([-+]?\d+)](.*?)[/size]/is'; | | 57: | $replace[11] = '<span style="font-size: $1%;">$2</span>'; | | 58: | | | 59: | // Font Color | | 60: | $pattern[12] = '/[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z-]+)](.*?)[/color]/is'; | | 61: | $replace[12] = '<span style="color: $1;">$2</span>'; | | 62: | | | 63: | // YouTube | | 64: | $pattern[13] = '/[youtube](.*?)[/youtube]/is'; | | 65: | $replace[13] = '<iframe width="560" height="315" src="http://www.youtube.com/embed/$1" allowfullscreen></iframe>'; | | 66: | | | 67: | return preg_replace($pattern, $replace, $string); | | 68: | } | | 69: | |

OpenCart API API documentation generated by ApiGen dev-master