How to use str_replace in laravel

how to use php function str_replace in laravel framework.

Array key names in table column names, so keys have "_" like first_name, last_name, etc. I want to remove these "_" in the blade file. my requirement is to replace the line in the .blade.php file.

I am trying to use this php code but it is useless.

<th>{{str_replace('_', ' ', $str)}}</th>

thank

+8
source share
4 answers

You can use php code in .blade.php file

try it

<th> <?=str_replace('_', ' ', $str)?> </th>
+14
source

What version of Laravel did you use?

For laravel 5.x use this

{!! str_replace('_', ' ', $str) !!}
+10
source

<th>{{-- */ echo str_replace('_', ' ', $str); /* --}}</th>

<th>{{-- */ $data = str_replace('_', ' ', $str); /* --}} {{$data}}</th>
0
source
use Illuminate\Support\Str;

$string = 'The event will take place between ? and ?';

$replaced = Str::replaceArray('?', ['8:30', '9:00'], $string);

// The event will take place between 8:30 and 9:00

For blade

 $item = "Free-Active";
{{ Str::replaceArray('free-', [''], $item) }}
0
source

Source: https://habr.com/ru/post/1569950/


All Articles