To add to @Kimzu answer, HTML entities with pre tags remain HTMl, so you should escape them:
pre
'<pre>' . htmlentities(print_r($array, true), ENT_QUOTES, 'UTF-8') . '</pre>'