preg replace - Why preg_replace() function isn't working properly? -


my php script is:

<?php     $string = '{controller}/{action}';     $pattern = '/\{([a-z]+)\}/i';     $replacement = '(?p<$1>[a-z-]+)';     echo preg_replace($pattern, $replacement, $string); ?> 

it showing result:

(?p[a-z-]+)\/(?p[a-z-]+) 

i expecting this:

(?p<controller>[a-z-]+)\/(?p<action>[a-z-]+) 

how can able this??


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -