PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, April 18, 2022

[FIXED] how to prevent html encoding(special chars) in laravel?

 April 18, 2022     laravel, php     No comments   

Issue

I have saved some html code in a my database ( using laravel 5.7 , Sqlite ) it saved but after that i want to show it , laravel encodes the special chars.

it have to return as a JSON string to angular without any encoding or changes.

I just want to prevent html special chars encoding.

I have tried this :

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

return ['content' => $content ];

But it doesn't work


Solution

in your controller

1 $post = Post::find($id);
2 $content =$post->content;
3 return redirect('/your-url')->with(['content'=>$content);

to return json

3. return response()->json($content);

in your blade file (please make sure that your file is saved with file-name.blade.php) you can just output content like thus

{!! $content !!}


Answered By - Emeka Okafor
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing