Function to clean POST variables


/ Published in: PHP
Save to your folder(s)

A snippet that allows you to easily clean up your code, done in one go by passing though a series of validations


Copy this code and paste it in your HTML
  1. // This function is used to clean POST variables.
  2. function clean($value) {
  3.  
  4. // If magic quotes not turned on add slashes.
  5.  
  6. // Adds the slashes.
  7. { $value = addslashes($value); }
  8.  
  9. // Strip any tags from the value.
  10. $value = strip_tags($value);
  11.  
  12. // Return the value out of the function.
  13. return $value;
  14.  
  15. } // End function.
  16.  
  17. //usage simple pass a string to the function and return the data back to the same variable
  18.  
  19. $sample = "<a href='#'>test</a>";
  20.  
  21. $sample = clean($sample);
  22.  
  23. echo $sample;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.