Matching placeholders
Moderator: General Moderators
sorry, typo
maybe unrecognized (because I edited too late on page 1):
Code: Select all
<?php
$a = array(1=>'x', 2=>'y', 11=>'z');
echo preg_replace('!(\d+)!e', '$a[\\1]', '1|2|11');
?>maybe unrecognized (because I edited too late on page 1):
volka wrote:pdo provides all of that. http://www.php.net/pdobartz wrote:Yes, I know that, but I'm building for a generalised DB abstraction, to easily swap out databases, using an Abstract Factory, and derived classes for each database flavour. So, I definately want to do my handling in PHP.
Last edited by volka on Fri Sep 01, 2006 13:27; edited 1 time in total
(\d+) : one or more digit(s) as one group
(\d)+ : I would have expected this to be an error. Don't no what it is.
You may also forget about the whole grouping thing (in this case) and use
(\d)+ : I would have expected this to be an error. Don't no what it is.
You may also forget about the whole grouping thing (in this case) and use
Code: Select all
<?php
$a = array(1=>'x', 2=>'y', 11=>'z');
echo preg_replace('!\d+!e', '$a[\\0]', '1|2|11');
?>wouldn't it be faster/easier/more stable anyway to use your class only as some kind of app<->pdo compatibilty layer and maybe replace it completely in the future?bartz wrote:And yes, I am aware that PDO does all that, but my lib has some additional features on which an entire app is built, so it's not very easy to swap my solution out for PDO/Pear::DB/and so on.
Thanks, your solution works, with some tweaks.
For the record, this is the line that made things work:
Topic may be closed.
For the record, this is the line that made things work:
Code: Select all
$query = preg_replace('/\:(\d+)/e', '$binds[\\1]', $query);