- preg_replace_callback: documentation ( source)
- explode: documentation ( source)
- str_rot13: documentation ( source)
<?php
$text = "[spoiler]Test\ntesting[/spoiler].";
$text = preg_replace_callback("/\[spoiler\](.*?)\[\/spoiler\]/",
function($match){
echo "test";
$lines = explode("\n", str_rot13($match[1]));
$output = "";
foreach ($lines as $line) {
$output .= "[spoiler]".$line."[/spoiler]";
}
return $output;
}, $text
);
echo $text;
?>