Bird
0
0

You want to display a user's bio that may contain HTML tags safely in a Blade template. Which is the best way to do this?

hard📝 state output Q15 of 15
Laravel - Views and Blade Templates
You want to display a user's bio that may contain HTML tags safely in a Blade template. Which is the best way to do this?
A<code>@php echo $user->bio; @endphp</code> without escaping.
B<code>{!! $user->bio !!}</code> to render HTML tags as HTML.
C<code>{{ $user->bio }}</code> to escape HTML tags.
D<code>{{ htmlspecialchars($user->bio) }}</code> inside Blade.
Step-by-Step Solution
Solution:
  1. Step 1: Understand security risks

    Displaying user input with HTML tags can cause security issues if not escaped.
  2. Step 2: Choose safe display method

    Using {{ $user->bio }} escapes HTML tags, preventing harmful scripts.
  3. Final Answer:

    {{ $user->bio }} to escape HTML tags. -> Option C
  4. Quick Check:

    Safe display with escaping = C [OK]
Quick Trick: Use {{ }} to escape user input and avoid XSS [OK]
Common Mistakes:
  • Using {!! !!} which renders raw HTML and risks XSS
  • Using raw PHP echo without escaping
  • Manually calling htmlspecialchars inside Blade

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes