Answer the question
In order to leave comments, you need to log in
How to make a substitution from an array with a key from a regular expression?
There is an array:
$routes = array( [1] => 'one', [2] => 'two', [3] => 'three' );
preg_replace("/\{a (\d+)}/g", "<a href=\"".$routes[\\1]."\">", $text);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question