| | |
php whitelist form validation??
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Last edited by stymiee; Jul 17th, 2007 at 6:53 pm.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
If the whitelist is entirely comprised of single characters, you can probably use to replace any occurrence of "#","$",or "%" with an empty string. Just put whatever characters you need to strip in there. If it's not a simple single character situation (i.e. you need to strip something like "<p>") then you'll have to go deeper into regex land to get there.
PHP Syntax (Toggle Plain Text)
preg_replace( "[^#$%]", "", $stringToFilter );
•
•
•
•
If the whitelist is entirely comprised of single characters, you can probably useto replace any occurrence of "#","$",or "%" with an empty string. Just put whatever characters you need to strip in there. If it's not a simple single character situation (i.e. you need to strip something like "<p>") then you'll have to go deeper into regex land to get there.PHP Syntax (Toggle Plain Text)
preg_replace( "[^#$%]", "", $stringToFilter );
PHP Syntax (Toggle Plain Text)
preg_replace( "/[#$%]/", "", $stringToFilter );
Sure, you can regular expressions to look for anything you want.
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
php Syntax (Toggle Plain Text)
preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );
replacing everything that is not char. or digit with whitespace
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
- th3 php wr3nch -
•
•
•
•
i guess this could work for your casephp Syntax (Toggle Plain Text)
preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );
replacing everything that is not char. or digit with whitespace
•
•
•
•
well what u did was the black list thing
and what i did is white one
it may look the same
but it is not!
Anyway, it does not matter. I posted to support that what you posted should work for him, he just needs to tune the pattern to include his acceptable characters
Last edited by Ezzaral; Jul 18th, 2007 at 1:19 pm.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Email addrress in Sessions
- Next Thread: Retrieve URL from address bar
| Thread Tools | Search this Thread |
5.2.10 action address ajax apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display domain dynamic echo email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image include insert integration ip java javascript joomla limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop paypal pdf php popup problem query radio random record recursion regex remote script search security server sessions sms soap sockets source space sql syntax system table tutorial update upload url validator variable video web xml youtube






