Page 2 of 2

Posted: Fri Sep 01, 2006 6:27 am
by bartz
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?

Posted: Fri Sep 01, 2006 6:30 am
by volka
sorry, typo

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:
bartz 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.
pdo provides all of that. http://www.php.net/pdo

Last edited by volka on Fri Sep 01, 2006 13:27; edited 1 time in total

Posted: Fri Sep 01, 2006 6:35 am
by bartz
Could you be so kind as to explain the difference between (\d)+ and (\d+)?

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.

Posted: Fri Sep 01, 2006 6:40 am
by volka
(\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

Code: Select all

<?php
$a = array(1=>'x', 2=>'y', 11=>'z');

echo preg_replace('!\d+!e', '$a[\\0]', '1|2|11');
?>
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.
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?

Posted: Fri Sep 01, 2006 6:45 am
by bartz
No, I'm fully confident in my code, and all the additional features. It's just that I encountered this bug for the first time now. Will try your solution now.

Posted: Fri Sep 01, 2006 6:56 am
by bartz
Thanks, your solution works, with some tweaks.
For the record, this is the line that made things work:

Code: Select all

$query = preg_replace('/\:(\d+)/e', '$binds[\\1]', $query);
Topic may be closed.