Re: Need help with regular expression
| From: | Al | Date: | Thu, 10 Jul 2008 13:48:07 +0000 |
| Subject: | Re: Need help with regular expression | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276580@lists.php.net to get a copy of this message | ||
Your description of the problem is confusing.
Do you simply want to delete a table row if it contains a variable, e.g., $var='bigfoto' and append "==REPLACEMENT==" ? Where $var can be anything you assign.
Maxim Antonov wrote:
Hello. But I need no td and tr inside regular expression It is a part of my templater. In real code it looks like: if(strlen($item[$key])<1){return preg_replace('#\{%%%.*?\{%'.$key.'%\}.*?%%%\}#is','',$tpl); }if one of $key inside {%%% .... %%%} points to empty array item - all section between {%%% %%%} must be deleted. Daniel Brown :On Wed, Jul 9, 2008 at 5:21 AM, Maxim Antonov <max@maxantonov.name> wrote:Hi, all! I try to use folowing regular expression: $out = preg_replace('#\{%%%.*?\{%bigfoto%\}.*?%%%\}#is','==REPLACEMENT==',$str);[snip!]I need result as: <tr><td>NAME:</td><td><input type="text" name="name" value="" size="80"/></td></tr> <tr><td>Foto:</td><td><input type="file" name="foto" value="{%foto%}" /> {%%%<br/><img alt="{%name%}" src="{%foto%}"/>%%%} </td></tr> ==REPLACEMENT==[snip!]To get it *exactly* as you've mentioned here, use this instead:<?php $out = preg_replace('/<tr><td>Big.*\{%%%.*\{%bigfoto%\}.*%%%\}.*<\/tr>/Uis','==REPLACEMENT==',$str); ?>