Jump to content

a mad quistion on stripslashes addslashes trim all together


redarrow

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.