note 86690 added to function.str-replace

From: Date: Wed, 29 Oct 2008 23:01:10 +0000
Subject: note 86690 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-145952@lists.php.net to get a copy of this message
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 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; } } ---- Server IP: 208.69.120.35 Probable Submitter: 96.224.167.245 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/86690 Del: integrated -- https://master.php.net/note/delete/86690/integrated Del: useless -- https://master.php.net/note/delete/86690/useless Del: bad code -- https://master.php.net/note/delete/86690/bad+code Del: spam -- https://master.php.net/note/delete/86690/spam Del: non-english -- https://master.php.net/note/delete/86690/non-english Del: in docs -- https://master.php.net/note/delete/86690/in+docs Del: other reasons-- https://master.php.net/note/delete/86690 Reject -- https://master.php.net/note/reject/86690 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145952) next »