Re: [PHP] PCRE - catching a caracter set in a negative class

2002-04-11 Thread Analysis & Solutions

Yo Maxim:

On Wed, Apr 10, 2002 at 10:48:42AM +0900, Maxim Maletsky wrote:
> 
> $text = ' 
> some text ... 
> {php}
>   echo "some funcy code to include he{re";
> {/php} 
> '; 
> 
> $out = preg_split("/(\{php}[^\{php}]*\{\/php})/i", $text, -1, 
> PREG_SPLIT_DELIM_CAPTURE); 

Your middle segment, "[^\{php}]*" is telling the system to took for any
character that's not a "{", "p", "h", or "}", and perhaps even a "\".  
So, any time it encounters one of those characters, the regex evaluates
to false.  It's best to replace it with ".*" and add the "ms" flags.

   $out = preg_split("/({php}.*{\/php})/ims", $text, -1, 
PREG_SPLIT_DELIM_CAPTURE);

I don't know if this does what you really want it to since what it does 
is kind of strange and you didn't specify what your goal is.

Good luck,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




[PHP] PCRE - catching a caracter set in a negative class

2002-04-09 Thread Maxim Maletsky


Hi all, 

I was scratching my head to accomplish the following perl regular 
expression. It doesn't want to catch me [^\{php}]. From what I understood 
reading the docs this is because in a negative class the caracters are being 
taken litteraly one by one and not as a set. I tied to enclose them by () by 
that didn't work eigher. What is the work around for this? 


here's a sample code: 


$text = ' 

some text ... 

{php}
echo "some funcy code to include he{re";
{/php} 

more text 


'; 

$out = preg_split("/(\{php}[^\{php}]*\{\/php})/i", $text, -1, 
PREG_SPLIT_DELIM_CAPTURE); 

 

Thanks, 

Maxim Maletsky 

Founder, Chief Developer
PHPBeginner.com (Where PHP Begins) 

www.PHPBeginner.com
[EMAIL PROTECTED] 

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