{"id":16000,"date":"2015-07-17T05:01:38","date_gmt":"2015-07-16T19:01:38","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=16000"},"modified":"2015-07-16T11:39:22","modified_gmt":"2015-07-16T01:39:22","slug":"php-mbstring-multibyte-string-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-mbstring-multibyte-string-primer-tutorial\/","title":{"rendered":"PHP Mbstring Multibyte String Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/mbstring_test.php\"><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'>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'>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'>&#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'>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'>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'>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'>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'>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'>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","protected":false},"excerpt":{"rendered":"<p>Our (Mac OS X laptop) local MAMP 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; &lt;?php phpinfo(); ?&gt; &#8230; and if, in doing this, you &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-mbstring-multibyte-string-primer-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":[1627,532,620,1560,744,1624,1625,932,997,1626,1319,1352],"class_list":["post-16000","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-characters","tag-google-translate","tag-internationalization","tag-language","tag-mamp","tag-mbstring","tag-multibyte-string","tag-php","tag-programming","tag-string","tag-tutorial","tag-utf-8"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16000"}],"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=16000"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16000\/revisions"}],"predecessor-version":[{"id":16005,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/16000\/revisions\/16005"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=16000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=16000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=16000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}