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

lewisbhs's avatar

Blade textarea with php tags

I was wondering what the proper way was to be able to have <?php tags aswell as code within a textarea for example - without the php trying to be ran. Have searched a few places but could not find a resolution.

Example:

<b>This is my code</b>
<textarea disabled>
<?php 
    echo 'My PHP code here'; // These PHP Tags and this code should not be run. It should just be displayed in its text form in the textarea.
?>
</textarea>

Thanks in advance.

0 likes
5 replies
somnathsah's avatar

put your code in tag {!! !!}. like below.

{!! !!}

Code in this tag will not get parsed.

lewisbhs's avatar

Apologies for bumping an old thread, the solution above did not seem to work. It was still parsing the string and returning the error:

Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Parse error: syntax error, unexpected '}' (View: 
Jaytee's avatar

Lmao, surely you actually did some googling within the 3 months you haven't responded?

hahaha

lewisbhs's avatar

Took a break from the project, ofcourse I've googled it. @Jaytee Any suggestions for whats causing the issue?

Example of whats not working:

<textarea disabled>
{!!
<?php 
    echo 'My PHP code here'; // These PHP Tags and this code should not be run. It should just be displayed in its text form in the textarea.
?>
!!}
</textarea>

Thanks.

Jaytee's avatar

Try using &lt; in place of < for the opening tag and &gt; in place of > for the closing tag.

Please or to participate in this conversation.