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(.*?) src=\"(.*?)\" (.*?)\>/is',
28 '/\<div(.*?)\>(.*?)\<\/div\>/is',
30 '/\<strong\>(.*?)\<\/strong\>/is',
31 '/\<a (.*?)href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
32 '/\<code\>(.*?)\<\/code\>/is',
33 '/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
34 '/\<span style=\"font-size:(.*?)\"\>(.*?)\<\/span\>/is',
35 '/\<blockquote\>(.*?)\<\/blockquote\>/is',
36 '/\<video(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/video\>/is',
37 '/\<audio(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/audio\>/is',
38 '/\<iframe(.*?) src=\"(.*?)\" (.*?)\>(.*?)\<\/iframe\>/is',
59 '[color="$1"]$2[/color]',
64 '[iframe]$1[/iframe]',
67 // Replace $htmltags in $text with $bbtags
68 $text = preg_replace ($htmltags, $bbtags, $s);
70 call_hooks('html2bbcode', $text);
72 // Strip all other HTML tags
73 $text = strip_tags($text);
78 function stripnl_exceptinpre($string)
80 // First, check for <pre> tag
81 if(strpos($string, '<pre>') === false)
83 return str_replace("\n","", $string);
86 // If there is a <pre>, we have to split by line
87 // and manually replace the linebreaks
89 $strArr=explode("\n", $string);
94 // Loop over each line
95 foreach($strArr as $line)
96 { // See if the line has a <pre>. If it does, set $preFound to true
97 if(strpos($line, "<pre>") !== false)
101 elseif(strpos($line, "</pre>") !== false)
106 // If we are in a pre tag, add line and also add \n, else add the line without \n
109 $output .= $line . "\n";