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