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