note 51384 deleted from function.sqlite-escape-string by cmb

From: Date: Mon, 02 Nov 2020 14:58:52 +0000
Subject: note 51384 deleted from function.sqlite-escape-string by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215725@lists.php.net to get a copy of this message
Note Submitter: soletan at toxa dot de ---- @minots: simplify what you are doing: <?php function sqlite_escape_array( &$arr ) { $invalid = array( 'argv', 'argc' ); foreach ( $arr as $key => $val ) if ( ( strtoupper( $key ) != $key ) && !is_numeric( $key ) && !in_array( $key, $invalid ) ) { if ( is_string( $val ) ) $arr[$key] = sqlite_escape_string( $val ); else if ( is_array( $val ) ) sqlite_escape_array( $arr[$key] ); } return $arr; } ?> I'm not sure if the condition is equivalent to yours, but this excludes any numeric key, any completely uppercase'd keys and some selected (argc and argv) special keys. In case of never passing $GLOBALS or $_SERVER as argument one might shorten everything to this as a "pipelined" version: <?php function sqlite_escape_array( $arr ) { foreach ( $arr as $key => $val ) if ( is_string( $val ) ) $arr[$key] = sqlite_escape_string( $val ); else if ( is_array( $val ) ) $arr[$key] = sqlite_escape_array( $val ); return $arr; } ?> PHP's syntax is more powerful than those of many other languages, even when it's supporting their one's as well.

« previous php.notes (#215725) next »