Complete expression

2

Well, I have something like this:

/^perfil[\/]?([0-9]{3})?[\/]?([a-z]{4,5})?[\/]?/i

You need to create a function that, when receiving the information, transform it into

perfil/431/abcd/
perfil/431/abcd
perfil/431/
perfil/431
perfil/
perfil

However, this function should accept several types of expressions like this, and transform them using the given parameters. How could I do that? I got to see the preg_replace function but I do not quite understand how to manipulate these expressions.

So what I need is a function that gets something like

/^perfil[\/]?([0-9]{3})?[\/]?([a-z]{4,5})?[\/]?/i
/^entrar[\/]?$/i
/^cadastro[\/]([0-9]{3})[\/]?$/i

And also receive the parameters of these expressions, for example, for

/^perfil[\/]?([0-9]{3})?[\/]?([a-z]{4,5})?[\/]?/i

I would send this expression, and would send 0 to 2 parameters, to fill ([0-9]{3}) and ([a-z]{4,5}) :

$expressao = "/^perfil[\/]?([0-9]{3})?[\/]?([a-z]{4,5})?[\/]?/i";
$valores = array(999, "zzzz");
$retorno = funcao($expressao, $valores);

And return in this case would be equal to:

perfil/999/zzz

One more example

$expressao = "/^cadastro[\/]([0-9]{3})[\/]?$/i";
$valores = array(999);
$retorno = funcao($expressao, $valores);

And in this case, return would be equal to:

cadastro/999/

That is, I send the expression and the values that I need to be placed in it, and the function would return the complete expression

    
asked by anonymous 08.12.2017 / 14:22

0 answers