Im trying to do something like sprintf() because I would like to have control over placeholders. The code I've posted works for the most part, but when I introduce content that has the same characters as my placeholders (%s and %i), it breaks to hell... Anyone got any ideas on how to fix, or tell me Im barking up the wrong tree... Thanks -------- <?php
$sql = 'select * from t1 where a like %s, b like %s and c like %s'; $data = array('%see me over there%', '%see you later%', 'just see'); preg_match_all('/%[si]/', $sql, $matches); $matches = $matches[0]; var_dump($sql); echo '<p>'; var_dump($data); echo '<p>'; foreach($data as $key => $chunk) { switch( $matches[ $key ] ) { case '%i': $chunk = (int)$chunk; break; case '%s': $chunk = "'" . (string)$chunk . "'"; break; default: continue; } $pos = strpos($sql, $matches[$key][0], $matches[$key][1]); $sql = substr_replace($sql, $chunk, strpos($sql, $matches[$key]), 2); } echo '<p>'; var_dump($sql); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php