Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

secondman's avatar

Print PHP Tags in Template

I'm doing some documentation and I want to echo out the entirety of my class file including the <?php tag.

How can I escape this so it'll print.

I've tried both {{ }} and {!! !!} but it still kills the app.

Thanks

0 likes
3 replies
secondman's avatar

LOL, the {{ double braces didn't echo in the post :P

usman's avatar

@vkronlein just use a pre tag and normal out of the box escaping should do it for your:

<?php $a = <<<'EOC'
<?php
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
    ]);
}
?>
EOC;
?>
<pre><?php echo e($a);?></pre>

Note: I have used the nowdoc syntax so that interpreter don't try to interpolate the $data variable inside the code.

Usman.

secondman's avatar
secondman
OP
Best Answer
Level 17

@usman it turned out all I needed to do was replace the < with it's equivalent &lt; and that took care of it.

Thanks for responding though I appreciate it.

Please or to participate in this conversation.