Skip to content

Instantly share code, notes, and snippets.

@mlebkowski
Created June 19, 2012 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlebkowski/2953233 to your computer and use it in GitHub Desktop.
Save mlebkowski/2953233 to your computer and use it in GitHub Desktop.
<?php
$str = "SQL :param1 :param2 END_SQL";
$params = array (
'param1' => 'param1 value',
'param2' => 'param2 value'
);
echo preg_replace_callback('/:([a-z0-9]+)/', function ($m) use ($params) {
return '\'' . mysql_escape_string($params[$m[1]]) . '\'';
}, $str) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment