{"id":65821,"date":"2024-12-01T03:08:00","date_gmt":"2024-11-30T17:08:00","guid":{"rendered":"https:\/\/www.rjmprogramming.com.au\/ITblog\/?p=65821"},"modified":"2024-11-30T11:21:59","modified_gmt":"2024-11-30T01:21:59","slug":"php-intl-class-datetime-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-intl-class-datetime-tutorial\/","title":{"rendered":"PHP Intl Class Datetime Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/i_eg.php\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Intl Class Datetime Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/intl_class_revisit.gif\" title=\"PHP Intl Class Datetime Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Intl Class Datetime Tutorial<\/p><\/div>\n<p>We&#8217;re back revisiting the PHP <a target=\"_blank\" href='https:\/\/www.php.net\/manual\/en\/book.intl.php' rel=\"noopener\">intl<\/a> <font size=1>&#8220;Internationalization&#8221;<\/font> class mentioned in &#8220;the AlmaLinux install feeling&#8221; <a title='PHP Mbstring Multibyte String and Intl Class Tutorial' href='#phpmmsict'>PHP Mbstring Multibyte String and Intl Class Tutorial<\/a> &#8230;<\/p>\n<ul>\n<li>now, that on AlmaLinux, it works for us &#8230; and &#8230;<\/li>\n<li>with a revisit of <a target=\"_blank\" title='intl_currency.html' href='https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/intl_currency.html' rel=\"noopener\">intl_currency.html<\/a> <font size=1>(featuring a <a target=\"_blank\" title='intl_currency.php' href='https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/intl_currency.php-GETME' rel=\"noopener\">&#8220;tweaked for AlmaLinux&#8221;<\/a> <a target=\"_blank\" title='intl_currency.php' href='https:\/\/www.rjmprogramming.com.au\/HTMLCSS\/intl_currency.php-GETME' rel=\"noopener\">intl_currency.php<\/a>)<\/font> seeing the intl clientside Javascript talents for Internationalization, in action<\/li>\n<\/ul>\n<p>Reading a bit, we cottoned onto three data items being central to Datetime PHP <a target=\"_blank\" href='https:\/\/www.php.net\/manual\/en\/book.intl.php' rel=\"noopener\">intl<\/a> usage being &#8230;<\/p>\n<ol>\n<li>locale<\/li>\n<li>timezone<\/li>\n<li>calendar <font size=1>&#8230; optional<\/font><\/li>\n<\/ol>\n<p> &#8230; and, so, we&#8217;re starting our &#8220;learning curve&#8221; (we got great help from <a target=\"_blank\" href='https:\/\/stackoverflow.com\/questions\/44693939\/incorrect-hijri-date-in-php-intl' title='Excellent advice, thanks' rel=\"noopener\">this excellent website<\/a> developing &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\nif (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {<br \/>\n $DateTime = new DateTime();<br \/>\n $IntlDateFormatter = new IntlDateFormatter(<br \/>\n                    urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),<br \/>\n                    IntlDateFormatter::FULL,<br \/>\n                    IntlDateFormatter::FULL,<br \/>\n                    urldecode($_GET['timezone']),<br \/>\n                    IntlDateFormatter::TRADITIONAL);<br \/>\n<br \/>\n echo '&lt;p&gt;' . $IntlDateFormatter-&gt;format($DateTime) . '&lt;\/p&gt;&lt;br&gt;&lt;br&gt;';<br \/>\n}<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230;) in today&#8217;s <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/i_eg.php_GETME\" rel=\"noopener\">&#8220;first draft&#8221;<\/a> &#8220;proof of concept&#8221; offering here, as a <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/i_eg.php\" rel=\"noopener\">PHP web application<\/a>, you can also try below &#8230;<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/i_eg.php\" style=\"width:90%;height:800px;\"><\/iframe><\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/php-intl-class-datetime-tutorial\/' rel=\"noopener\">PHP Intl Class Datetime Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpmmsict'>Previous relevant <a target=\"_blank\" title='PHP Mbstring Multibyte String and Intl Class Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-mbstring-multibyte-string-and-intl-class-tutorial\/' rel=\"noopener\">PHP Mbstring Multibyte String and Intl Class Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Mbstring Multibyte String and Intl Class Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test_again.jpg\" title=\"PHP Mbstring Multibyte String and Intl Class Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Mbstring Multibyte String and Intl Class Tutorial<\/p><\/div>\n<p>We&#8217;re revisiting the <a title='PHP Mbstring Multibyte String Primer Tutorial' href='#phpmmspt'>PHP Mbstring Multibyte String Primer Tutorial<\/a> of the past to see where we stand now with PHP 8 and &#8230;<\/p>\n<ul>\n<li><a target=\"_blank\" href='http:\/\/php.net\/manual\/en\/book.mbstring.php' title='Multibyte String Information' rel=\"noopener\">mbstring<\/a> &#8220;Multibyte String&#8221; extension &#8230; and &#8230;<\/li>\n<li><a target=\"_blank\" href='https:\/\/www.php.net\/manual\/en\/book.intl.php' rel=\"noopener\">intl<\/a> &#8220;Internationalization Functions&#8221; extension<\/li>\n<\/ul>\n<p> &#8230; and discovered that we can happily now have a chance incorporating these functionalities into PHP serverside logic into the future.  We tested this with <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php-GETME\" title='Click picture' rel=\"noopener\">a tweaked<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php-GETME\" title='Click picture' rel=\"noopener\">mbstring_test.php<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php\" title='Click picture' rel=\"noopener\">&#8220;old way&#8221; live run<\/a> and <a target=\"_blank\" href=\"http:\/\/65.254.95.247\/PHP\/mbstring_test.php\" title='Click picture' rel=\"noopener\">&#8220;new way&#8221; live run<\/a> via the writing of a couple of &#8220;proof of concepts&#8221; &#8230;<\/p>\n<ul>\n<li><a target=\"_blank\" href='http:\/\/php.net\/manual\/en\/book.mbstring.php' title='Multibyte String Information' rel=\"noopener\">mbstring<\/a> &#8220;Multibyte String&#8221; extension usage with <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/mbstring_test.php_GETME\" title='Click picture' rel=\"noopener\">&#8220;proof of concept&#8221;<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/mbstring_test.php\" title='Click picture' rel=\"noopener\">&#8220;old way&#8221; live run<\/a> and <a target=\"_blank\" href=\"http:\/\/65.254.95.247\/mbstring_test.php\" title='Click picture' rel=\"noopener\">&#8220;new way&#8221; live run<\/a><\/li>\n<li><a target=\"_blank\" href='https:\/\/www.php.net\/manual\/en\/book.intl.php' rel=\"noopener\">intl<\/a> &#8220;Internationalization Functions&#8221; usage with  <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/intl_basics.php_GETME\" title='Click picture' rel=\"noopener\">&#8220;proof of concept&#8221;<\/a> <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/intl_basics.php\" title='Click picture' rel=\"noopener\">&#8220;old way&#8221; live run<\/a> and <a target=\"_blank\" href=\"http:\/\/65.254.95.247\/intl_basics.php\" title='Click picture' rel=\"noopener\">&#8220;new way&#8221; live run<\/a><\/li>\n<\/ul>\n<p><img src='http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_intl.gif'><\/img><\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=\"_blank\" href='\/\/www.rjmprogramming.com.au\/ITblog\/php-mbstring-multibyte-string-and-intl-class-tutorial\/' rel=\"noopener\">PHP Mbstring Multibyte String and Intl Class Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpmmspt'>Previous relevant <a target=\"_blank\" title='PHP Mbstring Multibyte String Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-mbstring-multibyte-string-primer-tutorial\/' rel=\"noopener\">PHP Mbstring Multibyte String Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php\" rel=\"noopener\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Mbstring Multibyte String Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_primer.jpg\" title=\"PHP Mbstring Multibyte String Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP Mbstring Multibyte String Primer Tutorial<\/p><\/div>\n<p>Our (Mac OS X laptop) local <a target=\"_blank\" href='https:\/\/www.mamp.info\/' title='MAMP Apache\/PHP\/MySql web server landing page' rel=\"noopener\">MAMP<\/a> web server is an Apache\/PHP\/MySql web server.  In this environment you can find out a lot with some PHP code as per &#8230;<\/p>\n<p><code>&lt;?php <a target=\"_blank\" href='http:\/\/php.net\/manual\/en\/function.phpinfo.php' title='PHP phpinfo() method information' rel=\"noopener\">phpinfo();<\/a> ?&gt;<\/code><\/p>\n<p> &#8230; and if, in doing this, you find a reference to the <a target=\"_blank\" href='http:\/\/php.net\/manual\/en\/book.mbstring.php' title='Multibyte String Information' rel=\"noopener\">&#8220;mbstring&#8221;<\/a> Multibyte String Information functionality existing, you are a lucky candidate to introduce some internationalization code into your PHP code, for those occasions where the destination language uses a <a target=\"_blank\" title='UTF-8' href='https:\/\/en.wikipedia.org\/wiki\/UTF-8' rel=\"noopener\">UTF-8<\/a> character set where individual characters can not be described by the ascii character set from decimal 0 to decimal 255.   In other words, it takes more than one byte to describe each character of the language.  There are many languages like this, a few being the Chinese languages, Japanese and Korean.<\/p>\n<p>We followed a lot of the advice of the very useful <a target=\"_blank\" title='PHP mb_split (and mb_str_split) information' href='http:\/\/php.net\/manual\/en\/function.mb-split.php' rel=\"noopener\">link<\/a> (thanks) to create some PHP called &#8230;<\/p>\n<ul>\n<li><a target=\"_blank\" title='mbstring_test.php' href='http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php_GETME' rel=\"noopener\">mbstring_test.php<\/a><\/li>\n<\/ul>\n<p> &#8230; where we show what we always suspected but were too shy to ask, and didn&#8217;t flesh it out before &#8230; doh! &#8230; you can&#8217;t split a Chinese phrase&#8217;s characters into their individual characters and expect those characters individually translated bring you back to the sense of the Chinese phrase to start with.<\/p>\n<p>So we take the Chinese phrase \u706b\u8f66\u7968 (which translates into English as &#8220;Train tickets&#8221; &#8230; and we thank <a target=\"_blank\" title='Google Translate' href='http:\/\/transplate.google.com' rel=\"noopener\">Google Translate<\/a> for help with all this) and use PHP mbstring&#8217;s mb_str_split to properly split the Chinese into its constituent multibyte (UTF-8) characters (and along the way, show that PHP str_split messes up this same task, as you&#8217;d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.<\/p>\n<p>If this <i><b>exercise<\/b><\/i> makes you &#8230;<\/p>\n<ul>\n<li>a) fall on the floor laughing<\/li>\n<li>b) hit a gong with a huge hammer<\/li>\n<li>c) cook up some deep fried dumplings<\/li>\n<li>d) put the left chopstick in the right ear and the right chopstick in the left ear <font size=0>(please ask for adult supervision)<\/font> &#8230; translation: do not do this<\/li>\n<li>e) while reading you sweep the cat under the rug <font size=0>(no animals were harmed in the making of this blog posting)<\/font><\/li>\n<\/ul>\n<p> &#8230; then we&#8217;re here to tell you that you need to take a <a target=\"_blank\" title='Take a Bex ... and ...' href='https:\/\/www.youtube.com\/watch?v=BF6ffbz70SY' rel=\"noopener\">Bex<\/a> and have a lie down.<\/p>\n<p>We are just showing in PHP that if the mbstring functionality is available to you, that the mbstring library of functionality can help with some Internationalization issues you may be grappling with and that this PHP code you could try via this <a target=\"_blank\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php\" title='Click picture' rel=\"noopener\">live run<\/a> link.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d16000' onclick='var dv=document.getElementById(\"d16000\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=gimp\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d16000' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d64382' onclick='var dv=document.getElementById(\"d64382\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/intl\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d64382' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d65821' onclick='var dv=document.getElementById(\"d65821\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/internationalization\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d65821' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;re back revisiting the PHP intl &#8220;Internationalization&#8221; class mentioned in &#8220;the AlmaLinux install feeling&#8221; PHP Mbstring Multibyte String and Intl Class Tutorial &#8230; now, that on AlmaLinux, it works for us &#8230; and &#8230; with a revisit of intl_currency.html (featuring &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-intl-class-datetime-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[180,302,452,620,3172,4999,5000,1562,932,997,1986,1693,1319],"class_list":["post-65821","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-calendar","tag-datetime","tag-form","tag-internationalization","tag-intl","tag-intl-class","tag-intl-object","tag-locale","tag-php","tag-programming","tag-proof-of-concept","tag-timezone","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65821"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=65821"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65821\/revisions"}],"predecessor-version":[{"id":65828,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/65821\/revisions\/65828"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=65821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=65821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=65821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}