0
I am trying to use str_replace to change a part of the code,
$mudali = "li id=\"cabeca{$raiz}\" class=\"cabeca\"";
$mudali2 = "li id=\"pes{$raiz}\" class=\"pes\"";
echo $mudali; // resultado li id="cabeca-geral" class="cabeca"
echo $mudali2; // resultado li id="pes-geral" class="pes"
$rodape = str_replace($mudali, $mudali2, $rodape);
But it doesn’t work, but if I take it all down to the double quotes, the code works
$mudali = "cabeca{$raiz}";
$mudali2 = "pes{$raiz}";
echo $mudali; // resultado cabeca-geral
echo $mudali2; // resultado pes-geral
$rodape = str_replace($mudali, $mudali2, $rodape);
Someone knows how to fix?
But what exactly do you want to change? the id? the class? both?
– mau humor
I would like to change the id and class, but although echo generates the exact text of what I want to replace, with str_replace will not cost, only works if I double quote
– Alê Moraes
You can echo the footer variable and show us also?
– LF Ziron
Have you tried to use single quotes on your variables mudali and mudali2? in this way it will not be necessary to use "" before double quotes.
– Vinicius Zaramella
Footer echo is id="<li id="general-head" class="head"><p> ....
– Alê Moraes
Vinicius switched to single quotes, still not working, and I had to take the variable from inside the string, changed to $mudali = 'cabeca' . $root . '" class="head"';
– Alê Moraes
No way to use a double-quoted string in str_replace?
– Alê Moraes
The operation of str_replace is simple, in the first parameter, finds the second, if found, puts the third in the value equal to the second. Rethink how to use this to solve your problem.
– mau humor
I can change the text if I change the text without double quotes, for example, only the name of the general head id, but if I look for the text with id="general head' it does nothing
– Alê Moraes