Posted: Fri Sep 01, 2006 6:27 am
Please correct me if I am wrong, but doesn't (\d)+ matches one or more digits? So it'll still match the 1 of 10?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$a = array(1=>'x', 2=>'y', 11=>'z');
echo preg_replace('!(\d+)!e', '$a[\\1]', '1|2|11');
?>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
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.
Code: Select all
$query = preg_replace('/\:(\d+)/e', '$binds[\\1]', $query);