I need a simple and fast solution to replace nth occurrence (placeholder) in a string.
For example, nth question mark in sql query should be replaced with a provide
Instead of using question marks, why don't use markers like that :
$subject = "SELECT uid FROM users WHERE uid = :uid or username = :username"; $parameters = array( ':uid' => 42, ':username' => 'John', ); $subject = str_replace(array_keys($parameters), $parameters, $subject);