我正在尝试转换以下html
<div id="collapseOne" class="accordion-body collapse">
<div class="accordion-inner">
My Header1
</div></div>
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
My content1
</a></div>
像这样到下面的bbCode
[标题]我的标题1[标题/]
[内容]我的内容1[内容/]
[标题]我的标题2[标题/]
[内容]我的内容2[内容/]。. .
我怎样才能做到这一点 ?我正在写这门课但不工作
class BBCode
{
private $Tags = array(
'content','header');
/**
* Replaces all the BBCodes to HTML Codes
* param string $text: the text with BBCodes
*/
function ReplaceTag($Text)
{
$Replace_code['content'] = "<div id=\"collapseOne\" class=\"accordion-body collapse in\"><div class=\"accordion-inner\">$1</div></div>" ;
$Replace_code['header'] = "<div class=\"accordion-heading\"><a class=\"accordion-toggle\" data-toggle=\"collapse\" data-parent=\"#accordion2\" href=\"#collapseOne\">$1</a></div>" ;
// Deleting spaces from begging and end of string
$Done = trim($Text);
// Deleting all html code
$Done = htmlspecialchars($Done);
if(in_array("content",$this->Tags))
$Done = preg_replace("/\[content\](.*?)\[\/content\]/is", $Replace_code['content'], $Done);
if(in_array("header",$this->Tags))
$Done = preg_replace("(\[header\](.*?)\[\/header\])is", $Replace_code['header'], $Done);
$Done = nl2br($Done);
enter code here
return $Done;
}
}
问题是collapseOne,每对标签都要改变