21,891
社区成员
发帖
与我相关
我的任务
分享<?php
$s = highlight_string('程序代码',1); //或
$s = highlight_file('程序文件.php',1);
echo preg_replace_callback('/[{}]/', 'foo', $s);
function foo($v) {
static $deep = 0;
switch($v[0]) {
case '{':
$r = "{<div id='a$deep' onclick=show('a$deep','b$deep')>...</div><div id='b$deep' style='display:none' onclick=show('b$deep','a$deep')>";
$deep++;
break;
case '}':
$r = '</div>}';
break;
}
return $r;
}
echo <<< JS
<script>
function show(a, b) {
document.getElementById(a).style.display = 'none';
document.getElementById(b).style.display = '';
}
</script>
JS;
?>