Home » Php » How to use str_replace in laravel

How to use str_replace in laravel

Posted by: admin November 30, 2017 Leave a comment

Questions:

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

Answers:

You can use php code in .blade.php file

try like this

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

Questions:
Answers:

Which version of Laravel did you use?

For laravel 5.x, use this

{!! str_replace('_', ' ', $str) !!}

Questions:
Answers:

You may use this

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

OR

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