View Single Post
Old 01-22-2006, 08:21 AM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
DJMaze is on a distinguished road
Not entirely since [.*] is legit for any char so if you need those chars you need [\,\*]

The $ is a php case since "$foo" is as var $foo but '$foo' isn't, so you use "\$foo" or '$foo' to keep your coding everywhere the same and that prevents errors.

Example
PHP Code:
$string = 'You need $foo';
$foo = 'money';
preg_replace('#$foo#', '<?php echo $foo?>', $string);
eval($string);
preg_replace("#$foo#", "<?php echo $foo?>", $string);
eval($string);
preg_replace("#\$foo#", "<?php echo $foo?>", $string);
eval($string);
Outputs:

You need money
You need $foo
You need money
DJMaze is offline   Reply With Quote