如何在 Laravel 中使用 str_replace

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27774632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:50:37  来源:igfitidea点击:

How to use str_replace in laravel

laravellaravel-4

提问by Muneeb

how to use php function str_replace in laravel framework.

如何在 Laravel 框架中使用 php 函数 str_replace。

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.

我的表列名称上的数组键名称因此键具有 '_',如 first_name、last_name 等。我想在刀片文件中删除这些 '_'。我的要求是 .blade.php 文件中的字符串替换。

i am trying this php code but it's useless.

我正在尝试这个 php 代码,但它没用。

<th>{{str_replace('_', ' ', $str)}}</th>

thanks

谢谢

回答by Mohammed Saqib Rajput

You can use php code in .blade.php file

您可以在 .blade.php 文件中使用 php 代码

try like this

像这样尝试

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

回答by DIYDeveloper

Which version of Laravel did you use?

你用的是哪个版本的 Laravel?

For laravel 5.x, use this

对于laravel 5.x,使用这个

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

回答by Naeem Ijaz

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) }}

回答by absiddiqueLive

You may use this

你可以用这个

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

OR

或者

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