{"id":1234,"date":"2013-07-29T10:02:41","date_gmt":"2013-07-29T08:02:41","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1234"},"modified":"2013-07-29T10:02:41","modified_gmt":"2013-07-29T08:02:41","slug":"encode-accented-characters-of-an-url-to-the-hexadecimal-version-php","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2013\/07\/29\/encode-accented-characters-of-an-url-to-the-hexadecimal-version-php\/","title":{"rendered":"Encode accented characters of an URL to the hexadecimal version [PHP]"},"content":{"rendered":"<p>I&#8217;m facing an issue with some accented characters (like &#8216;\u00e9&#8217;, &#8216;\u00e8&#8217;, &#8216;\u00e0&#8217;, &#8230;) in an URL and I wanted to convert them to an hex value in PHP. I found nothing on Google so I have finally created my own function for my needs :<\/p>\n<pre class=\"brush:php\">\r\nfunction encodeURIHex($str) {\r\n  $len=strlen($str);\r\n  $ret=\"\";\r\n  for ($i=0; $i<$len; $i++) {\r\n    $dec = ord($str[$i]);\r\n    if ($dec > 191 &#038;& $dec &lt; 256) $ret .= \"%\".strtoupper(dechex($dec));\r\n    else $ret .= $str[$i];\r\n  }\r\n  return $ret;\r\n}\r\n<\/pre>\n<p>Example :<\/p>\n<pre class=\"brush:php\">\r\nencodeURIHex(\"M\u00e8re\"); \/\/ -> M%E8re\r\n<\/pre>\n<p>I used <a href=\"http:\/\/courshtml.free.fr\/donnees\/charset.htm\">this array<\/a> to find which values of dec version of my char I wanted to use (from 192 to 255 in my case).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m facing an issue with some accented characters (like &#8216;\u00e9&#8217;, &#8216;\u00e8&#8217;, &#8216;\u00e0&#8217;, &#8230;) in an URL and I wanted to convert them to an hex value in PHP. I found nothing on Google so I have finally created my own function for my needs : function encodeURIHex($str) { $len=strlen($str); $ret=&#8221;&#8221;; for ($i=0; $i 191 &#038;&#038; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[11,33],"tags":[151,25],"class_list":["post-1234","post","type-post","status-publish","format-standard","hentry","category-niveau-debutant","category-programmation","tag-niveau-debutant","tag-php"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1234"}],"version-history":[{"count":3,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1234\/revisions"}],"predecessor-version":[{"id":1237,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1234\/revisions\/1237"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}