$sHtml=ubb2html($_POST['elm1']);//htmlspecialchars
function showCode($match)
{
$match[1]=strtolower($match[1]);
if(!$match[1])$match[1]='plain';
$match[2]=preg_replace("/</",'<',$match[2]);
$match[2]=preg_replace("/>/",'>',$match[2]);
return '<pre class="prettyprint lang-'.$match[1].'">'.$match[2].'</pre>';
}
$sHtml=preg_replace_callback('/\[code\s*(?:=\s*((?:(?!")[\s\S])+?)(?:"[\s\S]*?)?)?\]([\s\S]*?)\[\/code\]/i','showCode',$sHtml);
function showFlv($match)
{
$w=$match[1];$h=$match[2];$url=$match[3];
if(!$w)$w=480;if(!$h)$h=400;
return '<embed type="application/x-shockwave-flash" src="mediaplayer/player.swf" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" quality="high" bgcolor="#ffffff" width="'.$w.'" height="'.$h.'" flashvars="file='.$url.'" />';
}
$sHtml=preg_replace_callback('/\[flv\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flv\]/i','showFlv',$sHtml);
php不懂啊。
也灭研究过php
就是不会啊。就是这个东东了。
string pattern_1 = @"(?i)\[code\s*(?:=\s*((?:(?!"")[\s\S])+?)(?:""[\s\S]*?)?)?\]([\s\S]*?)\[\/code\]";
Match m_1 = Regex.Match(sHtml,pattern_1);
string temp_1 = m_1.Groups[1].Value;
string temp_2 = m_1.Groups[2].Value;
string temp_3 = m_1.Groups[3].Value;
temp_1 = string.IsNullOrEmpty(temp_1) ? "plain" : temp_1.ToLower();
temp_2 = Regex.Replace(temp_2, @"<", "<");
temp_3 = Regex.Replace(temp_3, @">", ">");
sHtml = string.Format(@"<pre class=""prettyprint lang-{0}"">{1}</pre>",temp_1,temp_2);
string pattern_2 = @"(?i)\[flv\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!"")[\s\S])+?)(?:""[\s\S]*?)?\s*\[\/flv\]";
Match m_2 = Regex.Match(sHtml,pattern_2);
string w = m_1.Groups[1].Value;
string h = m_1.Groups[2].Value;
string url = m_1.Groups[3].Value;
w = string.IsNullOrEmpty(w) ? "480" : w;
h = string.IsNullOrEmpty(h) ? "400" : h;
sHtml = string.Format(@"<embed type=""application/x-shockwave-flash"" src=""mediaplayer/player.swf"" wmode=""transparent"" allowscriptaccess=""always"" allowfullscreen=""true"" quality=""high"" bgcolor=""#ffffff"" width=""{0}"" height=""{1}"" flashvars=""file={2}"" />",w,h,url);
string w = m_2.Groups[1].Value;
string h = m_2.Groups[2].Value;
string url = m_2.Groups[3].Value;