I can't find this in the forum archive...
I have a Perl reg exp that I'm very fond of for doing substitutions based on a hash lookup.
Here's the way you'd use it:
my $source = "foo, baz";
my %map = ( 'foo' => 'bar', 'baz' => 'bam' );
$source =~ s|@@([@]+)@@|$map{$1}|g;
$source prints "bar, bam";
Now I want to implement this in PHP and got as far as:
$source = preg_replace("/@@([@]+)@@/", $map, $source);
But that doesn't work, and nor do any of the other (to me) logical permutations of that:
preg_replace("/@@([@]+)@@/", $map[$1], $source)
preg_replace("/@@([@]+)@@/", "$map[$1]"...
And so forth.
What am I missing?
TIA<
jon