Re: Count and Preg_Replace Using Version 4.4.1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 04, 2005 at 07:00:00PM -0000, Shaun wrote:
> 
> "comex" <comexk@xxxxxxxxx> wrote in message 
> news:6bf32280512040808s16253e33r6cf972cec52c5a58@xxxxxxxxxxxxxxxxx
> > 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux