-2
I have a list of those values:
<li data-breadcrumb="Caixa 1 - Quarto 2 - Casa 3"> Conteúdo </li>
And I’d like to reverse their order in PHP.
I did a function
function inverte_breadcrumb($texto){
$texto = explode(' - ', $texto);
$texto = array_reverse($texto);
$texto = implode(' - ', $texto);
return $texto;
}
and with the preg_replace thought to do the following:
$novaslinhas = preg_replace("/data-breadcrumb="(.*)"/", 'data-breadcrumb="' . inverte_breadcrumb("$1") . '"', $novaslinhas);
But, it does not call the function.
Does anyone know why?
first, you are making a mess by delimiting the string with double quotes and at the same time using double quotes without escape. Second, you try to apply a function with the value "$1", it will even be called yes, but it is without effect (it will not reverse anything, because "$1" has no strokes. Put a
print_r($texto)
inside the inverte_breadcrumb function you will see that it will be called (after you fix the quotes). I hope that at these times of the comment you have already noticed that the function "reverses" will be called before replace, that is, it will not have the effect that you intend.– Bacco