Re: How can I check for characters in a $_POST[] variable?
| From: | Tommy Pham | Date: | Thu, 22 Sep 2011 12:31:58 +0000 |
| Subject: | Re: How can I check for characters in a $_POST[] variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314978@lists.php.net to get a copy of this message | ||
On Thu, Sep 22, 2011 at 7:55 AM, Eric <eric_justin_allan@cfl.rr.com> wrote:
> I have this problem when using php because my computer recognizes
> the characters "." and ".." as an existing file when I use file_exists.
> Also
> I want to check $_POST["username"] for characters other then A-Z a-z and
> 0-9.
> If it contains anything other then, I would like to prompt the user but
> I can't seam to use foreach properly and I don't know how to itterate
> through the post variable with a for loop while loop or do while loop.
$pattern = '/^[A-Za-z0-9]/';
/* http://php.net/control-structures.foreach
*/
foreach ($_POST as $key => $value)
{
/* http://php.net/function.preg-match */
if (preg_match($pattern, $value) > 0)
{
/* prompt user */
}
}