S
S
Svyatoslav2016-03-17 16:22:42
PHP
Svyatoslav, 2016-03-17 16:22:42

How to solve a bug with php on localhost?

there is a code

$str = '{controller}/{action}';
$str =  preg_replace('/\{([a-z]+)\}/', '(?P<\1>[a-z-]+)', $str);
echo $str;

in the online sandbox, everything works correctly on any versions of php, outputs:
(?P<controller>[a-z-]+)/(?P<action>[a-z-]+)
on localhost (installed xampp with php of different versions) output:
(?P[a-z-]+)/(?P[a-z-]+)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-03-17
@trixy

Maybe PHP can't output the spec. HTML characters, try using HTML entities:

<?php

$str = '{controller}/{action}';
$str =  preg_replace('/\{([a-z]+)\}/', '(?P&lt;\1&gt;[a-z-]+)', $str);
echo $str;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question