FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Dynamic backreferences, finding last in a group
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Dynamic backreferences, finding last in a group [message #179065] Sun, 09 September 2012 10:31 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
I'm working with preg_replace(), like so:

$pattern = array();
foreach ($filter as $org)
array_push($pattern, "/((<br>|\s)*)$org(er|in|...)/i");

$text = preg_replace($pattern, '$1$new$3', $text);


The issue I'm having is when $org contains a regex expression, like:

(D|d)ear

in which case (er|in|...) would now be $4 instead of $3.

The question is, is there a way that I can dynamically find the last backreference in the pattern, instead of referring to it strictly by number?

If not, I could always check to see if $org contains a (...), and then set the number accordingly. But this is in a foreach loop, and putting an strpos() in a loop like that seems slow; and then, I'm not sure that a backreference like this would works. Like:

if (strpos...) $num = "4";
else $num = "3";

$text = preg_replace($pattern, '$1$new$$num', $text);

Any suggestions?
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Php
Next Topic: Please help In if else while using array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 15:25:05 GMT 2024

Total time taken to generate the page: 0.05227 seconds