- don't use /^ .. $/ if you want to replace all occurences.  ^ and $ refer
to the very start and end of the whole string
  and make no sense at all - at least in this case. your regexp will not
match at all unless $var contains only a 
  single variable and nothing more
- either capture (something) by brackets, otherwise use \\0 instead of \\1
- you forgot the "&" : try  [\$\&]?\$
- [a-zA-Z][0-9]+  most variable names will not match this expr except
things like $a089666. do you name all of your
  variables like this ?!  [a-zA-Z_][\w\d\_]* is a good approach I guess but
some more characters are valid (RTFM:
  "Variables - BASICS")
- "$" is no good here as stated below


At 02:30 03.07.02 +0800, you wrote:
>On Wednesday 03 July 2002 01:59, Martin Clifford wrote:
>> Even this:
>> $output = preg_replace("/^[\$]{1,2}[a-zA-Z][0-9]+$/", "<b>\\1</b>", $var);
>> echo $output;
>> Doesn't work.  It just takes whatever you put into $var, then puts it into
>> $output, and outputs it to the screen.
>> I want to change anything resembling a PHP variable, i.e. $var, $$var or
>> &$var to <b>$var</b>.  Any ideas on how to do that?
>Don't use "" strings unless you need variable expansion.
>'/^\${1,2}[ ....
>... actually try RTFM, the section on variables gives you a regex definition 
>of acceptable PHP variables!
>Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
>Open Source Software Systems Integrators
>* Web Design & Hosting * Internet & Intranet Applications Development *
>To be sure of hitting the target, shoot first and, whatever you hit,
>call it the target.
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

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

Reply via email to