]> git.mxchange.org Git - friendica.git/blob - include/html2bbcode.php
Merge branch 'master' of git://github.com/friendika/friendika
[friendica.git] / include / html2bbcode.php
1 <?php
2
3 /**
4  * html2bbcode
5  */
6
7
8 function html2bbcode($s) {
9
10         // Tags to Find
11
12         $htmltags = array(
13                 '/\n/is',
14                 '/\<b\>(.*?)\<\/b\>/is',
15                 '/\<i\>(.*?)\<\/i\>/is',
16                 '/\<u\>(.*?)\<\/u\>/is',
17                 '/\<ul\>(.*?)\<\/ul\>/is',
18                 '/\<li\>(.*?)\<\/li\>/is',
19                 '/\<img(.*?) src=\"(.*?)\" (.*?)\>/is',
20                 '/\<div(.*?)\>(.*?)\<\/div\>/is',
21                 '/\<br(.*?)\>/is',
22                 '/\<strong\>(.*?)\<\/strong\>/is',
23                 '/\<a href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
24                 '/\<code\>(.*?)\<\/code\>/is',
25                 '/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
26                 '/\<blockquote\>(.*?)\<\/blockquote\>/is',
27                 '/\<video(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/video\>/is',
28                 '/\<audio(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/audio\>/is',
29
30         );
31
32         // Replace with
33
34         $bbtags = array(
35                 '',
36                 '[b]$1[/b]',
37                 '[i]$1[/i]',
38                 '[u]$1[/u]',
39                 '[list]$1[/list]',
40                 '[*]$1',
41                 '[img]$2[/img]',
42                 '$2',
43                 "\n",
44                 '[b]$1[/b]',
45                 '[url=$1]$3[/url]',
46                 '[code]$1[/code]',
47                 '[color="$1"]$2[/color]',
48                 '[quote]$1[/quote]',
49                 '[video]$1[/video]',
50                 '[audio]$1[/audio]',
51         );
52
53         // Replace $htmltags in $text with $bbtags
54         $text = preg_replace ($htmltags, $bbtags, $s);
55
56         call_hooks('html2bbcode', $text);
57
58         // Strip all other HTML tags
59         $text = strip_tags($text);
60         return $text;
61 }
62