0

I have this code which is meant to turn the value of a variable into a link by turning it to lowercase and then replacing all whitespaces with -

Here is my code:

@extends('layouts.base')
@section('pageTitle', 'Login')

@section('content')

Your search results are:<br><br>

@foreach($posts as $post)
    <a href="{{ strtolower(str_replace("",-, $post))}}">{{ $post }}</a><br>
@endforeach       

@endsection

But I get:

ErrorException (E_ERROR)
syntax error, unexpected ',' (View: C:\xampp2\htdocs\mysite\resources\views\search\index.blade.php)

My qustion is different from PHP parse/syntax errors; and how to solve them? beacuse it is a LARAVEL error not a php SYNTAX error!The solution to my question is supposed to be:{!! strtolower(str_replace(' ', '-', $post)) !!}.I was meant to write {!! rather than {{ as the opening blade tags and I mean you cannot do anything like that in pure php.

Constant
  • 574
  • 1
  • 5
  • 22
  • 2
    You did not wrap the dash in speech marks. `{{ $post }}
    `
    – Alex Mayo Apr 15 '19 at 14:50
  • 2
    `""` - is not a whitespace, `-` is not a dash, it is php __minus__. – u_mulder Apr 15 '19 at 14:50
  • @u_mulder I've gotten it now:`{!! str_replace('', '-', $post) !!}` sooo...... nobody cares if `-` is not a dash, it is php minus – Constant Apr 15 '19 at 14:53
  • @u_mulder unblock my question pls.It is a laravel error not php and I'v already gotten the answer plsssssss. – Constant Apr 15 '19 at 14:54
  • Perhaps you could use Laravel's `Illuminate\Support\Str::slug()` helper. – Thomas Apr 15 '19 at 15:22
  • @Thomas I have gotten the answer but u_mulder blocked by question or I would have posted the answer – Constant Apr 15 '19 at 15:28
  • @Titoxdboss Shouting really doesn't get you anywhere, and Laravel's a PHP framework. Your (now solved) issue was a PHP error, even if you wrote that bad PHP in a Laravel template. – ceejayoz Apr 15 '19 at 15:41
  • @ceejayoz I wasn't shouting.Why did u say that? – Constant Apr 15 '19 at 15:44
  • @Titoxdboss Your now-deleted comment was IN ALL CAPS, which is generally considered "shouting" on the Internet. – ceejayoz Apr 15 '19 at 15:45
  • @ceejayoz but no answer on that page could have solved my error – Constant Apr 15 '19 at 15:51
  • 2
    @Titoxdboss The exception you posted IS actually a PHP error (missing quotes around the dash/minus), even if it's used inside a blade template. Using `{!!` also shouldn't have any effect as long as you don't output anything that can get HTML encoded (which I don't think you are). So you should switch back to `{{ }}` [for security](https://laravel.com/docs/5.8/blade#displaying-data) if possible. And please try to be polite, even if others sometimes aren't. – Thomas Apr 15 '19 at 15:53

0 Answers0