How can I remove spaces in view?
How can I remove spaces in view?
I use laravel 5.3
My case is like this :
My code in view :
"
@if(isset($country))
{{ $country }}
@endif
@if(isset($city))
@if(isset($country))
-
@endif
{{ $city }}
@endif
"
The result like this :
" England - London "
I want the result like this :
"England - London"
How can I do it?
@Sagar, Yes, it just spaces
– Success Man
Jun 7 '17 at 8:36
Answer is here stackoverflow.com/questions/26146045/…
– kRicha
Jun 7 '17 at 8:37
It might be due to double quotation in new line
– Sagar Gautam
Jun 7 '17 at 8:37
@Sagar, Yes. I had find the best answer
– Success Man
Jun 7 '17 at 9:16
4 Answers
4
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
{{--*/ $finalString = ""; /*--}}
@if(isset($country))
{{--*/ $finalstring .= $country; /*--}}
@endif
@if(isset($city))
@if(isset($country))
{{--*/ $finalString .= ' - '; /*--}}
@endif
{{--*/ $finalString .= $city; /*--}}
@endif
"{{ $finalString }}"
Great. It works. Thanks
– Success Man
Jun 7 '17 at 9:16
I need you help. Look at this : stackoverflow.com/questions/45231810/…
– Success Man
Jul 21 '17 at 7:41
Have you tried using the trim function of PHP?
http://php.net/manual/en/function.trim.php
"
@if(isset($country))
{{ $country }}
@endif
@if(isset($city))
@if(isset($country))
-
@endif
{{ $city }}
@endif
"
It's the same. I want the result :
"England - London"
. You try read my question– Success Man
Jun 7 '17 at 8:41
"England - London"
It's the same. It does not work
– Success Man
Jun 7 '17 at 9:00
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!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What's the difference between result and expectation ? Just spaces ?
– Sagar Gautam
Jun 7 '17 at 8:36