Hi I'm trying the following code: $t = '12<-- AB_C -->'; $AB_C = 'abc'; echo preg_replace('/\<-- ([A-Z_]+) --\>/', "$$1", $t); Code (markup): I want to get "12abc" , but it outputs: 12$AB_C , so, it not recognize the replacement as dynamic variable. Is it any way to use the matched word in preg_replace() as a variable, or dynamic variable?
For those who look for a solution to this problem, the '/e' flag, which evalates the replacement, solved the problem, and returns the results i want, using: preg_replace('/\<-- ([A-Z_]+) --\>/e', "$$1", $t); Code (markup):
Thanks, i code regular in PHP and didn't no that! Thanks for letting us no after you found a solution!