How to use str_replace in laravel

牧云@^-^@ 提交于 2019-12-06 22:55:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!