The difference between daddslashes () and saddslashes () in PHP

Source: Internet
Author: User
  1. ----Saddslashes

  2. function Daddslashes ($string, $force = 0, $strip = FALSE) {
  3. Whether a string or array enforces removal
  4. If the magic reference is not turned on or $force is not 0
  5. if (! MAGIC_QUOTES_GPC | | $force) {
  6. if (Is_array ($string)) {//If it is an array then loop executes this function
  7. foreach ($string as $key = = $val) {
  8. $string [$key] = Daddslashes ($val, $force);
  9. }
  10. } else {
  11. If the magic reference is turned on or $force to 0
  12. The following is a ternary operator that executes Stripslashes minus the backslash character if $strip is true, and then executes the addslashes
  13. $strip is true, that is, the backslash character is first removed and then escaped for $_get,$_post,$_cookie and $_request $_request arrays contain the values of the first three arrays
  14. Why should we remove the $string first and then escape it, because sometimes $string have two backslashes, Stripslashes is to filter out the excess backslash
  15. $string = Addslashes ($strip? Stripslashes ($string): $string);
  16. }
  17. }
  18. return $string;
  19. }

  20. ------Saddslashes

  21. function Saddslashes ($string) {if (! MAGIC_QUOTES_GPC) {
  22. if (Is_array ($string)) {//If an array is escaped, the value in the set is recursively escaped
  23. foreach ($string as $key = = $val) {
  24. $string [$key] = saddslashes ($val);
  25. }
  26. } else {
  27. $string = Addslashes ($string); Escapes the single quotation mark ('), double quotation mark ("), backslash (\), and NUL (NULL character)
  28. }
  29. return $string;
  30. }else{
  31. return $string;
  32. }
  33. ?>

Copy Code

The point is: Saddslashes can be used to escape every data:

    1. function Saddslashes ($string) {
    2. if (Is_array ($string)) {
    3. foreach ($string as $key = = $val) {
    4. $string [$key] = saddslashes ($val);
    5. }
    6. } else {
    7. $string = Addslashes ($string);
    8. }
    9. return $string;
    10. }
    11. ?>
Copy Code
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.