Count and Preg_Replace Using Version 4.4.1

From: Date: Sat, 03 Dec 2005 10:12:35 +0000
Subject: Count and Preg_Replace Using Version 4.4.1
Groups: php.general 
Request: Send a blank email to php-general+get-226809@lists.php.net to get a copy of this message
Hi, The following code matches all occurences of <p> tags within an html page and wraps form tags around it: echo preg_replace( '/<p[^>]*>(.*?)<\/p>/ms', '<form name="form" target="_parent" action="'.$CFG->edit_pages_adm.'/index.php?action=edit_paragraph" method="post"> <input type="hidden" name="text" value="$1"> <p><a href="javascript:;" onclick="document.form.submit();">$1</a></p> </form>', file_get_contents($CFG->frontenddir_editable.'/'.$file) ); Unfortunately if there is more than one match the form won't submit because the forms have the same name. Does anyone know how can I modify this so that each occurence is numbered sequentially i.e. form'.$count.'... As I am using version 4.4.1 I don't have access to the count paramter in version 5.1. Thanks for your advice

« previous php.general (#226809) next »