我正在尝试使用下面显示的这个简单的BBcode解析器,但我不确定如何让它在我的网页上正常工作。我之前使用过一些使用了一些无法识别的函数的行。如:
require_once('parser.php'); // path to Recruiting Parsers' file
$parser = new parser; // start up Recruiting Parsers
$parsed = $parser-> p($mytext); // p() is function which parses
无法识别p()函数,因此不会解析任何内容。我正在使用文本编辑器,但它输出bbcode,我试图将其转换回html。你知道我应该使用什么代码来解析吗?我不是开发人员所以这很奇怪。
Here is the perser.php:
<?php
function bbcodeParser($bbcode){
/* bbCode Parser
*Syntax: bbcodeParser(bbcode)
*/
/* Matching codes */
$urlmatch = "([a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+)";
/* Basically remove HTML tag's functionality */
$bbcode = htmlspecialchars($bbcode);
/* Replace "special character" with it's unicode equivilant */
$match["special"] = "/\�/s";
$replace["special"] = '�';
/* Bold text */
$match["b"] = "/\[b\](.*?)\[\/b\]/is";
$replace["b"] = "<b>$1</b>";
/*many other properties as before: italics, colours, fonts etc.*/
/* Parse */
$bbcode = preg_replace($match, $replace, $bbcode);
/* New line to <br> tag */
$bbcode=nl2br($bbcode);
/* Code blocks - Need to specially remove breaks */
function pre_special($matches)
{
$prep = preg_replace("/\<br \/\>/","",$matches[1]);
return "�<pre>$prep</pre>�";
}
$bbcode = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism","pre_special",$bbcode);
/* Remove <br> tags before quotes and code blocks */
$bbcode=str_replace("�<br />","",$bbcode);
$bbcode=str_replace("�","",$bbcode); //Clean up any special characters that got misplaced...
/* Return parsed contents */
return $bbcode;
}
?>
答案 0 :(得分:0)
您是否尝试将p()
功能替换为bbcodeParser()
?看起来如果你这样做,它应该按预期工作:
require_once('parser.php'); // path to Recruiting Parsers' file
$parsed = bbcodeParser($mytext); // bbcodeParser() is function which parses