- htmlspecialchars: documentation ( source)
<?php
$File = new SplFileObject(__FILE__);
echo 'First dump: Just cast as string<br />';
echo '<pre>', htmlspecialchars((string) $File), '</pre>';
echo 'Ok, now let\'s iterate echoing out $line var created by foreach<br />';
echo '<pre>';
foreach($File as $line) {
echo htmlspecialchars($line) . '<br />';
}
echo '</pre>';
echo 'Ok, now let\'s echo out the object as string again';
echo '<pre>', htmlspecialchars((string) $File), '</pre>';