如何删除视图中的空格?

I use laravel 5.3

My case is like this :

My code in view :

<div class="alert alert-warning" role="alert">
    "
    @if(isset($country))
        {{ $country }}
    @endif
    @if(isset($city))
        @if(isset($country))
            -
        @endif
        {{ $city }}
    @endif
    "
</div>

The result like this :

" England - London "

I want the result like this :

"England - London"

How can I do it?

This wouldn't be the best method, but you could try setting the string to a variable and try the below code. Please verify whether the variable isn't containing spaces in your controller and send the trimmed variables to the view

<div class="alert alert-warning" role="alert">
    {{--*/ $finalString = ""; /*--}}
    @if(isset($country))
        {{--*/ $finalstring .= $country; /*--}}
    @endif
    @if(isset($city))
        @if(isset($country))
            {{--*/ $finalString .= ' - '; /*--}}
        @endif
        {{--*/ $finalString .= $city; /*--}}
    @endif
    "{{ $finalString }}"
</div>

Have you tried using the trim function of PHP? http://php.net/manual/en/function.trim.php

<div class="alert alert-warning" role="alert">
    <span>"</span>
    @if(isset($country))
        {{ $country }}
    @endif
    @if(isset($city))
        @if(isset($country))
            -
        @endif
        {{ $city }}
    @endif
    <span>"</span>
</div>

You can use:

@if(isset($country))
    @php($result = $country)
 @endif
 @if(isset($city))
     @if(isset($country))
         @php($result .= '-')
     @endif
         @php($result .= $city)
 @endif
{{$result}}

Good luck!