Jump to content

Replace with Dynamic variable in preg_replace


MarPlo

Recommended Posts

Hi

I'm trying the following code:

$t = '12<-- AB_C -->';
$AB_C = 'abc';
echo preg_replace('/\<-- ([A-Z_]+) --\>/', "$$1", $t);

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.