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

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

html - How to custom Bootstrap grid height? -