]> git.mxchange.org Git - friendica.git/blob - include/html2bbcode.php
fix some linebreak issues
[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                 '/\<pre\>(.*?)\<\/pre\>/is',
15                 '/\<p(.*?)\>/is',
16                 '/\<\/p\>/is',
17                 '/\<b\>(.*?)\<\/b\>/is',
18                 '/\<i\>(.*?)\<\/i\>/is',
19                 '/\<u\>(.*?)\<\/u\>/is',
20                 '/\<ul\>(.*?)\<\/ul\>/is',
21                 '/\<li\>(.*?)\<\/li\>/is',
22                 '/\<img(.*?) src=\"(.*?)\" (.*?)\>/is',
23                 '/\<div(.*?)\>(.*?)\<\/div\>/is',
24                 '/\<br(.*?)\>/is',
25                 '/\<strong\>(.*?)\<\/strong\>/is',
26                 '/\<a href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
27                 '/\<code\>(.*?)\<\/code\>/is',
28                 '/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
29                 '/\<blockquote\>(.*?)\<\/blockquote\>/is',
30                 '/\<video(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/video\>/is',
31                 '/\<audio(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/audio\>/is',
32
33         );
34
35         // Replace with
36
37         $bbtags = array(
38                 '',
39                 '[code]$1[/code]',
40                 '',
41                 "\n",
42                 '[b]$1[/b]',
43                 '[i]$1[/i]',
44                 '[u]$1[/u]',
45                 '[list]$1[/list]',
46                 '[*]$1',
47                 '[img]$2[/img]',
48                 '$2',
49                 "\n",
50                 '[b]$1[/b]',
51                 '[url=$1]$3[/url]',
52                 '[code]$1[/code]',
53                 '[color="$1"]$2[/color]',
54                 '[quote]$1[/quote]',
55                 '[video]$1[/video]',
56                 '[audio]$1[/audio]',
57         );
58
59         // Replace $htmltags in $text with $bbtags
60         $text = preg_replace ($htmltags, $bbtags, $s);
61
62         call_hooks('html2bbcode', $text);
63
64         // Strip all other HTML tags
65         $text = strip_tags($text);
66         return $text;
67 }
68