0

I uploaded a project from localhost to remote server and it didn't work. I found out that these lines are causing the error

if(!empty(ltrim(rtrim($string)))){
    $default_value = $string;
}

Then I have changed it to

$string = ltrim(rtrim($string));
if(!empty($string)){
    $default_value = $string;
}

And it's working. What is causing the error ?

No error is shown, only blank page. Changing ltrim(rtrim($string)) to just trim($string) doesn't help.

7
  • 1
    1. What is causing the error ? What error? 2. right and left trim combine it to a simple trim() call! Commented Apr 13, 2015 at 10:49
  • 1
    Why do both ltrim() and rtrim() when you can simply do trim() instead? Commented Apr 13, 2015 at 10:49
  • @MarkBaker I think because, he thinks that trim() also removes whitespace between 2 words. Commented Apr 13, 2015 at 10:52
  • 3
    What version of PHP are you using though? There were changes made to PHP 5.5.0 that allowed the results of expressions to be passed to empty: prior to that, you had to pass a variable Commented Apr 13, 2015 at 10:52
  • @MarkBaker PHP Version 5.4.36-0+deb7u3 Commented Apr 13, 2015 at 10:54

1 Answer 1

1

Until PHP 5.5 empty() only expected variables and from then on it also works with expressions. You must have PHP 5.5+ and your server runs a lower version.

Source: http://php.net/manual/en/function.empty.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.