Difference between daddslashes () and saddslashes () in php-php Tutorial

Source: Internet
Author: User
Differences between daddslashes () and saddslashes () in php

  1. // ---- Saddslashes

  2. Function daddslashes ($ string, $ force = 0, $ strip = FALSE ){
  3. // Whether to forcibly remove strings or arrays
  4. // If the magic reference is not enabled or $ force is not 0
  5. If (! MAGIC_QUOTES_GPC | $ force ){
  6. If (is_array ($ string) {// if it is an array, this function is executed cyclically.
  7. Foreach ($ string as $ key => $ val ){
  8. $ String [$ key] = daddslashes ($ val, $ force );
  9. }
  10. } Else {
  11. // If magic reference is enabled or $ force is 0
  12. // The following is a ternary operator. if $ strip is true, execute stripslashes to remove the backslash character and then execute addslashes.
  13. // $ Strip is true, that is, remove the backslash character and escape it as $ _ GET, $ _ POST, $ _ COOKIE and $ _ REQUEST arrays contain the values of the first three arrays.
  14. // Here, why do we remove the backslash and escape the $ string first, because sometimes $ string may have two backslashes, and stripslashes filters out unnecessary backslashes?
  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 the escape is an array, recursively escape the values in the array
  23. Foreach ($ string as $ key => $ val ){
  24. $ String [$ key] = saddslashes ($ val );
  25. }
  26. } Else {
  27. $ String = addslashes ($ string); // Escape single quotation marks ('), double quotation marks ("), backslash (\), and NUL (NULL character)
  28. }
  29. Return $ string;
  30. } Else {
  31. Return $ string;
  32. }
  33. ?>

Note: saddslashes can escape each 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. ?>

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.