note 51384 added to function.sqlite-escape-string

From: Date: Tue, 29 Mar 2005 12:19:29 +0000
Subject: note 51384 added to function.sqlite-escape-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-87139@lists.php.net to get a copy of this message
@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. ---- Manual Page -- http://www.php.net/manual/en/function.sqlite-escape-string.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51384 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51384&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51384&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51384&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51384&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51384&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51384&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87139) next »