Reputation: 5197
I have a string which contains a list of tags. Each tag redirects to another page. For example PS4, Xbox360, PC
But it also passes the empty space as %20Xbox360
. How can I remove this %20?
This is how I render tags:
@foreach($niz as $n)
<a href="/search?q={{$n}}" class="tags">{{$n}}{{$loop->last ? '' : ','}}</a>
@endforeach
Upvotes: 1
Views: 2853
Reputation: 9927
%20
is just whitespace url-encoded. So, urldecode()
it, then trim()
it:
<?php
$string = "%20Xbox360";
$string = urldecode($string);
$string = trim($string);
var_dump($string); // Xbox360
And to do this while echo
ing in Blade, just do it inside the curly braces:
<a href="/search?q={{ trim(urldecode($n)) }}" class="tags">{{$n}}{{$loop->last ? '' : ','}}</a>
Upvotes: 6