{}[]()<> and anyother that are specified are bad!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

{}[]()<> and anyother that are specified are bad!!!

Post by JellyFish »

Hello, I'm trying to, in one of my scripts, take a string/value from a $_POST super and post is to the database without the <>(){}[] characters included in it. If there is any function that checks the contents of a specified string and you can erase or bring a value of ture or false so that way I can do an if...else statement with it then I'd really love to know these kind of things. :) If anyone has some kind of way of accomplishing this then that'll be great! :D Thanks and all help is appreciated.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Code: Select all

<?
$codetoreplace = "y<o>(fff)yy{ggg}[ffff]"; // string with invalid characters
$fix = array("<",">","(",")","{","}","[","]"); // a array set up with all of the invalid characters
$new = str_replace($fix,' ',$codetoreplace); // replaces the invalid characters with a space (space can be taken out)
echo $new; //echos y o fff yy ggg ffff
?>
Last edited by nickman013 on Wed Mar 01, 2006 1:21 pm, edited 2 times in total.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Yea! This just might work. Thanks nick I'll reply if something goes wrong ( I highly doubt that though). :)
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Yes! It works! Your a ginius!!! (Please correct me on the word ginius) Thank you so much. This is one of the most perfect post I ever had it's exectly what I needed!
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

EasyGoing wrote:Yes! It works! Your a ginius!!! (Please correct me on the word ginius) Thank you so much. This is one of the most perfect post I ever had it's exectly what I needed!
genius
Post Reply