问题
how to use php function str_replace in laravel framework.
My array key names on table columns name so keys have '_' like first_name, last_name etc. i want to remove these '_' in blade file. my requirement is string replace in .blade.php file.
i am trying this php code but it's useless.
<th>{{str_replace('_', ' ', $str)}}</th>
thanks
回答1:
You can use php code in .blade.php file
try like this
<th> <?=str_replace('_', ' ', $str)?> </th>
回答2:
Which version of Laravel did you use?
For laravel 5.x, use this
{!! str_replace('_', ' ', $str) !!}
回答3:
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) }}
回答4:
You may use this
<th>{{-- */ echo str_replace('_', ' ', $str); /* --}}</th>
OR
<th>{{-- */ $data = str_replace('_', ' ', $str); /* --}} {{$data}}</th>
来源:https://stackoverflow.com/questions/27774632/how-to-use-str-replace-in-laravel