- preg_replace_callback: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- str_rot13: documentation ( source)
<?php
$text = "[spoiler] \n \nTst. \n \nTestt. \n \nTEstst \n \nTESTST \nESTET \n \n[/spoiler]";
$text = preg_replace_callback("(\[spoiler\](.*?)\[\/spoiler\])is",
function($match){
$lines = explode("\n", str_rot13($match[1]));
foreach ($lines as &$line) {
if (!empty($line)) $line = "[spoiler]".$line."[/spoiler]";
}
unset($line);
$output = implode("\n",$lines);
return $output;
}, $text
);
echo $text;
?>