Replace text with srt_replace using double quotation marks

0

I'm 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 does not work, but if I pull everything up to double quotation marks, 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);

Does anyone know how to fix it?

    
asked by anonymous 22.04.2016 / 03:11

1 answer

1

It probably has some difference in $rodape that is causing the replacement to fail. Spaces, tabs, accents, something like that. I suggest rewriting all these snippets, where $rodape is created, being careful. To debug the possible difference:

print "HEX1:" . bin2hex($mudali);
print "HEX2:" . bin2hex($rodape);
    
22.04.2016 / 03:59