Re: Count and Preg_Replace Using Version 4.4.1

From: Date: Sun, 04 Dec 2005 19:31:10 +0000
Subject: Re: Count and Preg_Replace Using Version 4.4.1
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-226843@lists.php.net to get a copy of this message
On Sun, Dec 04, 2005 at 07:00:00PM -0000, Shaun wrote: > > "comex" <comexk@gmail.com> wrote in message > > news:6bf32280512040808s16253e33r6cf972cec52c5a58@mail.gmail.com... > > form'.$count.'... > You can use preg_replace_callback or the e pattern modifier to let you > run php code for the replacement: > http://us3.php.net/manual/en/function.preg-replace-callback.php > > http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php > > Hi Comex, > > Thanks for your reply, I have modified the code so I have a call back > function: > > echo = preg_replace_callback( '/<p[^>]*>(.*?)<\/p>/ms', > "callback", > file_get_contents($_GET['file']) ); > > function callback($matches){ > return > '<form name="form" target="_parent" > ... > > But I still can't see how I can increment a value in each return string? function callback($matches) { static $i = 0; // <-- maintains counter within function scope $i++; return "<form name="form$i">....</form>"; } btw, i've been meaning to mention this in the last few posts of yours, but have you considered using DOM to make this happen. When ever I see a regex solution for parsing an html document, it makes me cringe. Curt. -- cat .signature: No such file or directory

« previous php.general (#226843) next »