note 86690 deleted from function.str-replace by philip

From: Date: Wed, 07 Oct 2009 07:58:08 +0000
Subject: note 86690 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161446@lists.php.net to get a copy of this message
Note Submitter: Konstantin ---- Well, suffering without parameter replace ability like in plsql sql = > "select * from x where id = %1"; execute sql, var1; (sorry for pseudo) here is a function just wrote for my self using str_replace, let me know if there is a better way for such generic function <?php function sql_prep() { $args = func_get_args(); $sql = array_shift($args); $args_cnt = func_num_args(); $found=0; foreach($args as $key=>$value) { $rep_str = "\$sql = str_replace('%$key','$value',\$sql,\$count);"; eval($rep_str); if($count) { $found++; } } if($found == $args_cnt-1) { return $sql; } else { echo "WARNING: number of subs=".($args_cnt-1)." does not match number of reps=$found"; return $sql; } } ?>

« previous php.notes (#161446) next »