【发布时间】:2014-05-19 17:24:34
【问题描述】:
我写了类似[spoiler=Spoiler Title]text inside the Spoiler[/spoiler]
并使用preg_replace_callback("/\[spoiler=(.*)\](.*)\[\/spoiler\]/Usi", 'BBCode_spoiler', $text); 创建一个真正的剧透,一个或多个剧透的结果是:
<script type="text/javascript">
function show_0() {
if(document.getElementById("0").style.display == "inline-block")
document.getElementById("0").style.display = "none";
else document.getElementById("0").style.display = "inline-block"; }
</script>
<a href="javascript:show_0();"><i>Show Spiler:</i> <b>Spoiler Title</a></b><br>
<div id="0" style="display: none; min-width: 100px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; background-color: #FFFFFF; color: #000000;">
Text inside the Spoiler
</div>
我如何使它与扰流板一起工作成为扰流板
喜欢[spoiler=Spoiler Title][spoiler=Second Spoiler]Another Text[/spoiler][/spoiler]
我当前的函数没有剧透返回到剧透中
<script type="text/javascript">
function show_0() {
if(document.getElementById("0").style.display == "inline-block")
document.getElementById("0").style.display = "none";
else document.getElementById("0").style.display = "inline-block"; }
</script>
<a href="javascript:show_0();"><i>Show Spiler:</i> <b>Spoiler Title</a></b><br>
<div id="0" style="display: none; min-width: 100px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; background-color: #FFFFFF; color: #000000;">
[spoiler=Second Spoiler]Another Text</div>[/spoiler]
我的回调函数是
<?php
// Spoiler
$counter = 0;
function BBCode_spoiler($hits) {
global $central_lang;
global $counter;
$title = htmlentities(trim($hits[1]));
$text = htmlentities($hits[2]);
$return = "<script type=\"text/javascript\">";
$return .= "function show_".$counter."() {";
$return .= "if(document.getElementById(\"".$counter."\").style.display == \"inline-block\") document.getElementById(\"".$counter."\").style.display = \"none\";";
$return .= "else document.getElementById(\"".$counter."\").style.display = \"inline-block\"; }";
$return .= "</script>";
$return .= "<a href=\"javascript:show_".$counter."();\"><i>".$central_lang['bbcodes']['spoiler']['text'].":</i> <b>".$title."</a></b><br>";
$return .= "<div id=\"".$counter."\" style=\"display: none; min-width: 100px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; background-color: #FFFFFF; color: #000000;\">".$text."</div>";
$counter++;
return $return; }
?>
我尝试做的输出看起来像这样
<script type="text/javascript">
function show_0() {
if(document.getElementById("0").style.display == "inline-block")
document.getElementById("0").style.display = "none";
else document.getElementById("0").style.display = "inline-block"; }
</script>
<a href="javascript:show_0();"><i>Show Spoiler:</i> <b>Spoiler Title</a></b><br>
<div id="0" style="display: none; min-width: 100px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; background-color: #FFFFFF; color: #000000;">
<script type="text/javascript">
function show_1() {
if(document.getElementById("1").style.display == "inline-block")
document.getElementById("1").style.display = "none";
else document.getElementById("1").style.display = "inline-block"; }
</script>
<a href="javascript:show_1();"><i>Show Spoiler:</i> <b>Second Spoiler</a></b><br>
<div id="1" style="display: none; min-width: 100px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; background-color: #FFFFFF; color: #000000;">
Another text
</div>
</div>
希望我的问题有答案,谢谢!
【问题讨论】:
标签: php regex preg-replace-callback