PDA

View Full Version : [PHP][RegExp] More characters



Hyperized
June 13th, 2009, 07:18 AM
Hey people I ran into a little hiccup and I hope one of you can help me out.

I'm trying to build a query filter to replace ':1', ':2' etc with the input of the function. Example:

SELECT * FROM tickets WHERE ticket_id = :1Then use:


$binds = func_get_args();
foreach($binds as $index => $name)
{
$this->query = preg_replace("/ \:$index/", " '".$name."'", $this->query);
}To replace the query placeholders with real values (as delivered with the function).

Now this is working like a charm, however I run into a problem once I hit the 10's or 100's
For example, the return value of :10 will be seen as 'valueof1'0. I figure my regular expression only takes the first character that is detected in account. How do I make it so it detects the first and if possible any next nummerical character till whitespace or the end of the string, ánd still include it in the replace process?

Thanks in advance!
Hyperized

icio
June 14th, 2009, 06:02 PM
Make the replacements in the opposite order:

for ($index = count($binds)-1; $index >= 0; $index--) {
$name = $binds[$index];
// ...
}

Hope that helps :thumb: