JohnHenry
JohnHenry

Reputation: 39

Unwanted control characters

The user input in my website an email address sometimes appears like this and is saved in the database [email protected]Â Â Â Â Â Â Â Â Â Â Â Â or similar. In the resulting printout it is like this [email protected] I think these are space characters from a non-UTF-8 charset. I have tried using a regex which I am sure is wrong

$email = preg_replace('/[\t ]/', '', $email); 

and I have tried

$email=trim($email);

Can someone please guide me on this?

Upvotes: 1

Views: 88

Answers (2)

JohnHenry
JohnHenry

Reputation: 39

Brilliant. The filter did it. I tried the regex but it had no effect. BTW the UTF-8 statement is in the HTML head. I guess that forces it but not sure. I didn't try the urlencode but it is something to remember with future problems.

Upvotes: 0

Roberto Bisello
Roberto Bisello

Reputation: 1235

you can use filter_var($email, FILTER_SANITIZE_EMAIL) to remove all invalid chars or filter_var($email, FILTER_VALIDATE_EMAIL) if you prefer to check the email and warning the user if there is some problem

Upvotes: 1

Related Questions