Re: [PHP] Need help with regular expression
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 [EMAIL PROTECTED] wrote: Hi, all! I try to use folowing regular expression: $out = preg_replace('#\{%%%.*?\{%bigfoto%\}.*?%%%\}#is','==REPLACEMENT==',$str); [snip!] I need result as: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput 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('/trtdBig.*\{%%%.*\{%bigfoto%\}.*%%%\}.*\/tr/Uis','==REPLACEMENT==',$str); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Need help with regular expression
-Original Message- From: Maxim Antonov [mailto:[EMAIL PROTECTED] Sent: Thursday, July 10, 2008 4:24 AM To: php-general@lists.php.net; Daniel Brown Subject: Re: [PHP] Need help with regular expression 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. ---8--- snip Maxim, You could try using a capture group, and re-assemble the match with the match group inbetween your {%%% %%%} omitted. Just an idea. Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help with regular expression
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 [EMAIL PROTECTED] wrote: Hi, all! I try to use folowing regular expression: $out = preg_replace('#\{%%%.*?\{%bigfoto%\}.*?%%%\}#is','==REPLACEMENT==',$str); [snip!] I need result as: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput 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('/trtdBig.*\{%%%.*\{%bigfoto%\}.*%%%\}.*\/tr/Uis','==REPLACEMENT==',$str); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help with regular expression
On Wed, Jul 9, 2008 at 5:21 AM, Maxim Antonov [EMAIL PROTECTED] wrote: Hi, all! I try to use folowing regular expression: $out = preg_replace('#\{%%%.*?\{%bigfoto%\}.*?%%%\}#is','==REPLACEMENT==',$str); It not work as I need. Please tell me - what I do wrong? I have string: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput type=file name=foto value={%foto%} / {%%%br/img alt={%name%} src={%foto%}/%%%} /td/tr trtdBig foto:/tdtdinput type=file name=bigfoto value= / {%%%br/img alt={%name%} src={%bigfoto%}/%%%} /td/tr I need result as: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput type=file name=foto value={%foto%} / {%%%br/img alt={%name%} src={%foto%}/%%%} /td/tr ==REPLACEMENT== And I have this result: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput type=file name=foto value={%foto%} / ==REPLACEMENT== /td/tr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'm sure it won't be this easy because of who knows what (like inheriting code, etc), but why not just use something easier like: $replace = array( '{%key1%}' = 'value1', '{%key2%}' = 'value2' ); $html = str_replace( array_keys($replace), array_values($replace), file_get_contents('tpl.html') ); Or the easiest is to just use raw php code seeing as php is a templating language. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help with regular expression
On Wed, Jul 9, 2008 at 5:21 AM, Maxim Antonov [EMAIL PROTECTED] wrote: Hi, all! I try to use folowing regular expression: $out = preg_replace('#\{%%%.*?\{%bigfoto%\}.*?%%%\}#is','==REPLACEMENT==',$str); [snip!] I need result as: trtdNAME:/tdtdinput type=text name=name value= size=80//td/tr trtdFoto:/tdtdinput 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('/trtdBig.*\{%%%.*\{%bigfoto%\}.*%%%\}.*\/tr/Uis','==REPLACEMENT==',$str); ? -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php