Re: Count and Preg_Replace Using Version 4.4.1

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

 



"Curt Zirzow" <czirzow@xxxxxxxxx> wrote in message 
news:20051204193110.GF5243@xxxxxxxxxxxxxxx
> 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

Hi Curt,

Thanks for your reply. So basically I do something like:

$doc = new DOMDocument();
$doc->loadHTML($file);

$p = $doc->getElementsByTagName('p');

How would then wrap the following around each <p> tag:

<form name="form" target="_parent" 
action="/index.php?action=edit_paragraph&file='.$_GET['file'].'" 
method="post">
    <input type="hidden" name="old_html" 
value="'.htmlentities($matches[0]).'">
    <p><a href="javascript:;" 
onclick="document.form.submit();">'.$matches[1].'</a></p>
</form>

BTW if its not obvious I am trying to create a CMS that lets users edit 
anything within a <p> tag! 

-- 
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