Posted By

daveismyname on 09/27/09


Tagged

cleanpostvariables


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
aleksanderek


Function to clean POST variables


 / Published in: PHP
 

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

  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  

You need to login to post a comment.