Differences between daddslashes () and saddslashes () in php
// ---- Saddslashes
- Function daddslashes ($ string, $ force = 0, $ strip = FALSE ){
- // Whether to forcibly remove strings or arrays
- // If the magic reference is not enabled or $ force is not 0
- If (! MAGIC_QUOTES_GPC | $ force ){
- If (is_array ($ string) {// if it is an array, this function is executed cyclically.
- Foreach ($ string as $ key => $ val ){
- $ String [$ key] = daddslashes ($ val, $ force );
- }
- } Else {
- // If magic reference is enabled or $ force is 0
- // The following is a ternary operator. if $ strip is true, execute stripslashes to remove the backslash character and then execute addslashes.
- // $ 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.
- // 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?
- $ String = addslashes ($ strip? Stripslashes ($ string): $ string );
- }
- }
- Return $ string;
- }
// ------ Saddslashes
- Function saddslashes ($ string) {if (! MAGIC_QUOTES_GPC ){
- If (is_array ($ string) {// if the escape is an array, recursively escape the values in the array
- Foreach ($ string as $ key => $ val ){
- $ String [$ key] = saddslashes ($ val );
- }
- } Else {
- $ String = addslashes ($ string); // Escape single quotation marks ('), double quotation marks ("), backslash (\), and NUL (NULL character)
- }
- Return $ string;
- } Else {
- Return $ string;
- }
- ?>
Note: saddslashes can escape each data:
- Function saddslashes ($ string ){
- If (is_array ($ string )){
- Foreach ($ string as $ key => $ val ){
- $ String [$ key] = saddslashes ($ val );
- }
- } Else {
- $ String = addslashes ($ string );
- }
- Return $ string;
- }
- ?>
|