Jump to content


Photo

a mad quistion on stripslashes addslashes trim all together


  • Please log in to reply
6 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 September 2006 - 07:43 PM

advance thank you.

i have read that most good programmers make a function to addslases stripslashes and trim

is the following possable.

<?php
$redarrow=stripslashes(addslashes(trim($_POST['redarrow'])));
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 yungbloodreborn

yungbloodreborn
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationCalifornia

Posted 13 September 2006 - 07:58 PM

I'm sure that's possible, I've nested function calls like that before in PHP. But I fail to see the reason for putting addslashes in a stripslashes call with nothing in between.

-YB

#3 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 13 September 2006 - 08:02 PM

Yeah, what you're doing there is effectively this...

stripslashes from the string
adding slashes to the string
triming white space from the string

Don't take them away and then put them back.  Other then that, you would have no issues combining functions together to do that for you.  IMHO it would be best to put those inside of your own function so you could call it whenever you wanted to like this...

function cleanString($String) {
  return addslashes(trim($String));
}

Just use like this...

echo cleanString($_POST['redarrow']);
I'm considered good looking in some countries

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 September 2006 - 08:11 PM

see i understand the concept that wht i asked as you no i am only asking as seen on here and wondered.

now as you have provided a good example of the function format i want to no is it possable to make up somethink in the function that will cheek all the varables but as one value and not hundreds.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 13 September 2006 - 08:18 PM

Are you putting numbers into the function?  If so you should use use something else...if you're trying to round just use the round() function.
I'm considered good looking in some countries

#6 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 13 September 2006 - 08:31 PM

<?php
  // MakeDBSafe
  // $val - the value to make safe for insertion into the database
  // RETURN: $val modified to be safe for insertion into a database
  function MakeDBSafe($val){
    if(!is_numeric($val)){
      $val = "'" . trim(addslashes($val)) . "'";
    }
    return $val;
  }
?>

PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#7 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 13 September 2006 - 08:32 PM

I reread your last post, if you're asking is there a generic function that you can write that will validate any and all data, yes you can.  It will be long, ugly, and messy.  I'd recommend several smaller sections and possibly taking advantage of regexps for that.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users