Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 2000051

Re: [PHP3] Regular ****ing expressions From: Michael Dearman (mdearman <email protected>)
Date: 05/15/00

Mark Selby wrote:
>
> Hi PHP'ers,
>
> I had a reply earlier but guess it was a php4
> function.
> In $str, I want to replace any occurances of
> '<:$varname:>' with ' $varname ', so I can then
> 'print("$str");' and see the actual variable values.
> I need to be sure it started with '<:$' and ended with
> ':>'
>
> Thanks in advance.
> Mark.
>
> <HTML><H1>Test of Regular Expressions</H1>
> <?
> $str = "Hello this <:$somevar:> is a test of
> <:$someothervar> regular expressions";

Check out the ereg_replace in the manual.

Here's what it looks like using a preg.
But, you'll have to change those double quotes in the $str
assignment to single quotes. Well, only way I could get it to
work. Anyone? It's that '$' for the var that causes probs.

     $pat = '/<:\$(\w+):>/';
     $replace = '\\1';

     $new_str = preg_replace($pat, $replace, $str);

     $print $new_str;
  ?>
  </HTML>

It should work on your example string. No guarantee on other
input.

M. Dearman

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>