the bulletin board software converted the pipe html entity to a pipe,
on this line:
$_POST[$key] = str_replace("|", "|", $value);
the second | should be:
& # 1 2 4 ;
i added spaces between each character to prevent it from being converted to the pipe again, you will need to remove the spaces between characters.