Note that there are some explanatory texts on larger screens.

plurals
  1. POMy script works fine, but I'm confused about why I have to use utf8_decode()
    primarykey
    data
    text
    <p>I am confused about the behavior of utf8_decode() and just want a little clarification. I hope that's ok.</p> <p>Here's a simple HTML form that I'm using to capture some text and save it to my MySQL database (which uses the utf8_general_ci collation):</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="update.php" method="post" accept-charset="utf-8"&gt; &lt;p&gt; Title: &lt;input type="text" name="title" id="title" accept-charset="utf-8" size="75" value="" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>As you can see I've got this coded up with charset=utf8 in the appropriate places. We accept text that includes diacritics (eg., ñ, ó, etc.). In the end, we run a little script on all text input to check for diacritics and change them to HTML entities (eg., ñ becomes &amp;ntilde;). </p> <p>When input is received by my script, I first have to do utf8_decode($input) and then run my little script to check for and change diacritics as needed. Everything works fine. I'm curious as to why I have to run the decode on this input. I understand that utf8_decode converts a string encoded in UTF-8 to ISO-8859-1. I want to make sure - <em>even though everything works fine (or so I think)</em> - that I'm not doing something screwy that will catch up to me later. For instance, that I'm sending ISO-8859-1 encoded characters to be stored in my database that is set up to store/serve UTF-8 characters. Should I do something like run utf8_encode() on the string that my diacritics-to-entities script returns? Eg:</p> <pre><code>$string = utf8_decode($string); $search = explode(",","À,È,Ì,Ò,Ù,à,è,ì,ò,ù,Á,É,Í,Ó,Ú,Ý,á,é,í,ó,ú,ý,Â,Ê,Î,Ô,Û,â,ê,î,ô,û,Ã,Ñ,Õ,ã,ñ,õ,Ä,Ë,Ï,Ö,Ü,Ÿ,ä,ë,ï,ö,ü,ÿ,Å,å,Æ,æ,ß,Þ,þ,ç,Ç,Œ,œ,Ð,ð,Ø,ø,§,Š,š,µ,¢,£,¥,€,¤,ƒ,¡,¿"); $replace = explode(",","&amp;Agrave;,&amp;Egrave;,&amp;Igrave;,&amp;Ograve;,&amp;Ugrave;,&amp;agrave;,&amp;egrave;,&amp;igrave;,&amp;ograve;,&amp;ugrave;,&amp;Aacute;,&amp;Eacute;,&amp;Iacute;,&amp;Oacute;,&amp;Uacute;,&amp;Yacute;,&amp;aacute;,&amp;eacute;,&amp;iacute;,&amp;oacute;,&amp;uacute;,&amp;yacute;,&amp;Acirc;,&amp;Ecirc;,&amp;Icirc;,&amp;Ocirc;,&amp;Ucirc;,&amp;acirc;,&amp;ecirc;,&amp;icirc;,&amp;ocirc;,&amp;ucirc;,&amp;Atilde;,Ntilde;,&amp;Otilde;,&amp;atilde;,&amp;ntilde;,&amp;otilde;,&amp;Auml;,&amp;Euml;,&amp;Iuml;,&amp;Ouml;,&amp;Uuml;,&amp;Yuml;,&amp;auml;,&amp;euml;,&amp;iuml;,&amp;ouml;,&amp;uuml;,&amp;yuml;,&amp;Aring;,&amp;aring;,&amp;AElig;,&amp;aelig;,&amp;szlig;,&amp;THORN;,&amp;thorn;,&amp;ccedil;,&amp;Ccedil;,&amp;OElig;,&amp;oelig;,&amp;ETH;,&amp;eth;,&amp;Oslash;,&amp;oslash;,&amp;sect;,&amp;Scaron;,&amp;scaron;,&amp;micro;&amp;cent;,&amp;pound;,&amp;yen;,&amp;euro;,&amp;curren;,&amp;fnof;,&amp;iexcl;,&amp;iquest;"); $new_input = str_replace($search, $replace, $string); return utf8_encode($new_input); // right now i just return $new_input. </code></pre> <p>Appreciate any insight anyone has to offer about this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload