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
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.
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.
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.
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.
Which version of Laravel did you use?
For laravel 5.x, use this
{!! str_replace('_', ' ', $str) !!}
You can use php code in .blade.php file
try like this
<th> <?=str_replace('_', ' ', $str)?> </th>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With