Click to See Complete Forum and Search --> : preg_replace help


jacen6678
03-25-2005, 11:58 AM
I need some help using preg_replace().

I have a string (ex: $my_string) that will contain a sub-string like (ex: '{my_substring}' ).

I want to replace all instances of {my_substring} with the value $my_array['my_substring']. I believe that this can be done using the /e modifier but I dont know how to write the reg-ex. Can someone tell me the preg_replace() function call?

jacen6678
03-25-2005, 03:10 PM
Solved it... incase anyone is curious, the solution is:
$output = preg_replace( '/(\{)(\w+)(\})/e', "\$my_array['\\2']", $my_string );