Diamonte Diamonte - 1 year ago 77
PHP Question

PHP IF OR AND not working

I have problems to make IF OR statement properly, in this case it does not matter if I use || or "OR".

I have now:

if($email == '' || (!filter_var($email, FILTER_VALIDATE_EMAIL)))

I get error
PHP Fatal error: Call to undefined function \xa0() in

if I change to
if($email == '' || !filter_var($email, FILTER_VALIDATE_EMAIL))

I get error
PHP Parse error: syntax error, unexpected '!' in

Answer Source

This error message Call to undefined function \xa0() in looks a lot like encoding types are the source of your problem. The \xA0 character is a bugger:

\xa0 is actually non-breaking space in Latin1 (ISO 8859-1), also
chr(160). You should replace it with a space. When .encode('utf-8'), it
will encode the unicode to utf-8, that means every unicode could be
represented by 1 to 4 bytes.Jun 12, 2012

from Python: Removing \xa0 from string?

The problem is you can't see it either because it's a special "whitespace" that was most probably inserted during a Crtl+C / Crtl+V from some strange IDE or website.

This should remove them all from your file and replace them with good whitespaces:

file_put_contents('your-script-cleaned.php', str_replace('\\x0a', ' ', file_get_contents('your-script-original.php')))

An IDE search & replace could do the trick just as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download