PHP Replacing Character Inside String With Variable -


in few words, trying replace "?" value inside variable , doesn't work. please help.

    $string = "? red ? blue";     $count = 1;      update_query($string, array($v = 'violets', $r = 'roses'));       function update_query($string, $values){          foreach ( $values $val ){              str_replace('?', $val, $string, $count);             }          echo $string;     } 

the output getting is: ? red ? blue

frustrated people not paying attention, compelled answer question properly.

str_replace replace instances of search string. after violets, there nothing left roses replace.

sadly str_replace not come limit parameter, preg_replace does. can better still preg_replace_callback, so:

function update_query($string, $values){     $result = preg_replace_callback('/\?/', function($_) use (&$values) {         return array_shift($values);     }, $string);     echo $string; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -