0
function xmlEscape($string) {
    return str_replace(array('&', '<', '>', '\'', '"','/','“','”'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;','&#x2F;', '&quot;', '&quot;'), $string);
}

I tried the str_replace() function in php but it is not recognising these double quotation marks.

The rest of all characters are escaping only problem is with ” “ these 2 special characters

For example, i gave the input to $string='23”'.

So it is stored in the MYSQL database as "23â€".

I want the str_replace() output to be "23&quot;"

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • These are UTF-8 characters. There's nothing specifically Italian about them. It's unclear what you mean by "it is not even recognising" them? What is "it" in that sentence? PHP? The finished XML? What actual output do you get? Does your XML document support UTF-8? Not very much is clear in your post. – ADyson Feb 13 '20 at 16:31
  • @ADyson "it" refers to str_replace() function in php – GAURAV DESHPANDE Feb 13 '20 at 16:33
  • 1
    I can't reproduce that. Demo: http://sandbox.onlinephpfunctions.com/code/f189e5b59e9bf4ba03546c932f4eeb54f854eaa0 - it works fine. Please give a sample of the input data you're using, and how you create the XML file itself, and the final output of your code, currently. – ADyson Feb 13 '20 at 16:36
  • 1
    Can you also show the actual code you are using to set the XML value (not this function, but the XML creation of elements/document) – Nigel Ren Feb 13 '20 at 16:39
  • https://stackoverflow.com/questions/3957360/generating-xml-document-in-php-escape-characters may be useful, but not sure yet. – Nigel Ren Feb 13 '20 at 16:41
  • Judging by the `23â€` it looks like maybe the database isn't set to use utf-8 properly and could be corrupting the data. Have a read of https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – ADyson Feb 13 '20 at 16:45
  • i have already set the collation of MySQL to utf8_general_ci while creating the database table – GAURAV DESHPANDE Feb 13 '20 at 16:49
  • And the accepted answer at the link I just gave you says _Specify the utf8mb4 character set on all tables and text columns in your database. This makes MySQL physically store and retrieve values encoded natively in UTF-8. Note that MySQL will implicitly use utf8mb4 encoding if a utf8mb4_* collation is specified (without any explicit character set)._ . Seriously, have a read of the whole article. There may be other things you need to do. – ADyson Feb 13 '20 at 16:56

0 Answers0