Home > Blockchain >  How to add to blade (Laravel, PHP) PHP-code as text with other background?
How to add to blade (Laravel, PHP) PHP-code as text with other background?

Time:11-28

I want add PHP-code as text in laravel blade. (Something like adding code in stackoverflow)

in blade file I have:

{!! nl2br($article->body_ru) !!}

in $article->body_ru I'm add

huijlhgfyuhukik
rfthkgjb
ftygyjh
<code>
<?php

namespace App\Services;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Collection;
use stdClass;

class WeatherService
{

}
</code>

And I'm want to see something like this in body:

huijlhgfyuhukik rfthkgjb ftygyjh

<?php

namespace App\Services;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Collection;
use stdClass;

class WeatherService
{

}

CodePudding user response:

Sorry but I am unable to completely understand what you are trying to achieve here. If you could elaborate, that might help people in answering with some relevant work-around.

If you just want to print this in the output: "huijlhgfyuhukik rfthkgjb ftygyjh"

Put this text in a compact variable, let's call it $output.

function index() {
    $output = "huijlhgfyuhukik rfthkgjb ftygyjh";
    return compact( 'output' );
}

And use it in the blade file like this:

{!! $output !!}

CodePudding user response:

Blade files get compiled to raw PHP files and they can contain PHP. This would be the same exact thing if you had a regular PHP file and you wanted to output that text. You could use a HTML entity, &lt;, instead of the opening < for the <?php tag so it doesn't go into PHP mode and will be rendered as < in the HTML by the browser:

<code>
&lt;?php
...
</code>
  • Related