Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use str_replace in laravel

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

like image 785
Muneeb Avatar asked Jan 05 '15 06:01

Muneeb


People also ask

What is the use of Str_replace in PHP?

The str_replace() function replaces some characters with some other characters in a string. This function works by the following rules: If the string to be searched is an array, it returns an array. If the string to be searched is an array, find and replace is performed with every array element.

How to replace string in Laravel?

Replacing strings in Laravel with the str() helper x', '3. x'); $string = 'The quick brown fox jumps over the lazy dog. '; str($string)->replaceFirst('the', 'a'); => 'a quick brown fox jumps over the lazy dog. ' str($string)->replaceLast('the', 'a'); => 'The quick brown fox jumps over a lazy dog.

How can I replace multiple characters in a string in PHP?

Approach 1: Using the str_replace() and str_split() functions in PHP. The str_replace() function is used to replace multiple characters in a string and it takes in three parameters. The first parameter is the array of characters to replace.

What is DD function in Laravel?

dd stands for "Dump and Die." Laravel's dd() function can be defined as a helper function, which is used to dump a variable's contents to the browser and prevent the further script execution.


2 Answers

Which version of Laravel did you use?

For laravel 5.x, use this

{!! str_replace('_', ' ', $str) !!}
like image 191
DIYDeveloper Avatar answered Sep 23 '22 08:09

DIYDeveloper


You can use php code in .blade.php file

try like this

<th> <?=str_replace('_', ' ', $str)?> </th>
like image 25
Mohammed Saqib Rajput Avatar answered Sep 23 '22 08:09

Mohammed Saqib Rajput