note 46526 added to function.rawurlencode

From: Date: Thu, 14 Oct 2004 07:31:06 +0000
Subject: note 46526 added to function.rawurlencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-78528@lists.php.net to get a copy of this message
Oftentimes when building a user system for a site you ask users for a username which must not contain any spaces or punctuation. My reason for this, though it may not be the only reason, is so that I can use their usernames in URLs such as: mysite.com/users/username. So when a user is registering, rather than do a regex check for spaces and punctuation, I find it quicker and easier to use urlencode(). if(urlencode($username) != $username) echo "Your username may not contain spaces or punctuation"; If urlencode() changes the $username whatsoever, the condition will be met and the user will get the error. Just a shortcut, but a surefire way to make sure a user's chosen name will be usable in a URL later on. Like I said though, there may be other reasons, and characters that should be accounted for. ---- Manual Page -- http://www.php.net/manual/en/function.rawurlencode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46526 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46526&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46526&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78528) next »