8 function html2bbcode($s) {
11 // only keep newlines from source that are within pre tags
13 $s = stripnl_exceptinpre($s);
19 '/\<pre\>(.*?)\<\/pre\>/is',
22 '/\<b\>(.*?)\<\/b\>/is',
23 '/\<i\>(.*?)\<\/i\>/is',
24 '/\<u\>(.*?)\<\/u\>/is',
25 '/\<ul\>(.*?)\<\/ul\>/is',
26 '/\<li\>(.*?)\<\/li\>/is',
27 '/\<img(.*?)width: *([0-9]+)(.*?)height: *([0-9]+)(.*?)src=\"(.*?)\" (.*?)\>/is',
28 '/\<img(.*?)height: *([0-9]+)(.*?)width: *([0-9]+)(.*?)src=\"(.*?)\" (.*?)\>/is',
29 '/\<img(.*?)src=\"(.*?)\"(.*?)width: *([0-9]+)(.*?)height: *([0-9]+)(.*?)\>/is',
30 '/\<img(.*?)src=\"(.*?)\"(.*?)height: *([0-9]+)(.*?)width: *([0-9]+)(.*?)\>/is',
31 '/\<img(.*?) src=\"(.*?)\" (.*?)\>/is',
32 '/\<div(.*?)\>(.*?)\<\/div\>/is',
34 '/\<strong\>(.*?)\<\/strong\>/is',
35 '/\<a (.*?)href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
36 '/\<code\>(.*?)\<\/code\>/is',
37 '/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
38 '/\<span style=\"font-size:(.*?)\"\>(.*?)\<\/span\>/is',
39 '/\<blockquote\>(.*?)\<\/blockquote\>/is',
40 '/\<video(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/video\>/is',
41 '/\<audio(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/audio\>/is',
42 '/\<iframe(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/iframe\>/is',
57 '[img=$2x$4]$6[/img]',
58 '[img=$4x$2]$6[/img]',
59 '[img=$4x$6]$2[/img]',
60 '[img=$6x$4]$2[/img]',
67 '[color="$1"]$2[/color]',
72 '[iframe]$1[/iframe]',
75 // Replace $htmltags in $text with $bbtags
76 $text = preg_replace ($htmltags, $bbtags, $s);
78 call_hooks('html2bbcode', $text);
80 // Strip all other HTML tags
81 $text = strip_tags($text);
86 function stripnl_exceptinpre($string)
88 // First, check for <pre> tag
89 if(strpos($string, '<pre>') === false)
91 return str_replace("\n","", $string);
94 // If there is a <pre>, we have to split by line
95 // and manually replace the linebreaks
97 $strArr=explode("\n", $string);
102 // Loop over each line
103 foreach($strArr as $line)
104 { // See if the line has a <pre>. If it does, set $preFound to true
105 if(strpos($line, "<pre>") !== false)
109 elseif(strpos($line, "</pre>") !== false)
114 // If we are in a pre tag, add line and also add \n, else add the line without \n
117 $output .= $line . "\n";