Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

a mad quistion on stripslashes addslashes trim all together

Recommended Posts

advance thank you.

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

is the following possable.

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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']);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[code]
<?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;
  }
?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.