Page 1 of 1

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

Posted: Wed Mar 01, 2006 12:41 pm
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.

Posted: Wed Mar 01, 2006 12:55 pm
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
?>

Posted: Wed Mar 01, 2006 1:16 pm
by JellyFish
Yea! This just might work. Thanks nick I'll reply if something goes wrong ( I highly doubt that though). :)

Posted: Wed Mar 01, 2006 1:24 pm
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!

Posted: Wed Mar 01, 2006 1:47 pm
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