How do I convert these strings to PHP?

Asked

Viewed 387 times

1

I have the following instructions ....

echo $parcelamento . "<br>"; 
echo utf8_encode($parcelamento) . "<br>";
echo utf8_decode($parcelamento) . "<br>";

... that return respectively this:

ou 12x de R$ 21,58 sem juros no cartÃÂão
ou 12x de R$ 21,58 sem juros no cartÃÂÃÂÃÂão
ou 12x de R$ 21,58 sem juros no cartão

Can anyone tell me how I will return the term card?

Another solution would be to replace card for card within the proposed sentence but I do not know how to develop any of the solutions.

I’m running a PHP for this XML

  • 1

    You defined the charset to utf-8? like this: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />.

  • strange... Probably $installment already comes corrupted. line 1 (4utf8); row 2 (5utf8); row 3 (3utf8). As @Qmechanic73 suggested; the wrong encoding can fix one (2utf8) -- the problem must come from behind.

  • How you are getting and "parsing" this XML?

  • 1

    I suggest you edit the question and add the source of the data as well as the Encode/charset of the data. The way it is, let’s just keep kicking some possibility.. unproductive

1 answer

1


The function utf8_encode() should be called iso88591_to_utf8() so as not to confuse.

In your case, you do not need to use this function, as your data is already in UTF-8. It is good to leave your data in UTF-8, as you already do, until the last possible moment.

To make sure you don’t "pollute" your XML environment and avoid accidental conversions, declare your HTML to UTF-8 as well, at @qmechanik’s suggestion:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Your XML is already explicitly identified as UTF-8:

<?xml version="1.0" encoding="UTF-8"?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.