Re: how to remove user imput backslashes?

From: Date: Wed, 26 Jul 2000 19:39:12 +0000
Subject: Re: how to remove user imput backslashes?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-8385@lists.php.net to get a copy of this message
Juan Luis Baptiste M. wrote:
If a user puts in a text field a '\' it will broke my script, hoy can I prevent this?
If your problem is processing in your script breaking because of special characters, you can use addslashes() to escape special characters. That should replace \ with \\. If you set magic_quotes_gpc to on in your php.ini, PHP will automagically do this for you for incoming variables. This is quite handy as it can eliminate much of the risk from using untrusted user input in database queries. If you need to encode something for display and need things like < to not break your HTML, use htmlspecialchars(). This will convert things like < to their HTML equivalent (e.g. &lt;). htmlentities() is similar but works on a wider number of characters beyond those strictly necessary to prevent things like form fields from breaking. Chris

« previous php.general (#8385) next »