gpt4 book ai didi

php - 如何防止laravel中的html编码(特殊字符)?

转载 作者:行者123 更新时间:2023-12-04 13:20:01 28 4
gpt4 key购买 nike

我在我的数据库中保存了一些 html 代码(使用 laravel 5.7,Sqlite)
它保存了,但在那之后我想显示它,laravel 对特殊字符进行编码。

它必须以 JSON 字符串形式返回到 angular,无需任何编码或更改。

我只想防止 html 特殊字符编码。

我试过这个:

$post = Post::find($id);
$content = html_entity_decode($post->content);

return ['content' => $content ];

但它不起作用

最佳答案

在你的 Controller 中

1 $post = Post::find($id);
2 $content =$post->content;
3 return redirect('/your-url')->with(['content'=>$content);
返回json
3. return response()->json($content);
在您的 Blade 文件中(请确保您的文件使用 file-name.blade.php 保存)
你可以像这样输出内容
{!! $content !!}

关于php - 如何防止laravel中的html编码(特殊字符)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54600119/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com