PHP Intl Class Peer to Peer World Map Tutorial

PHP Intl Class Peer to Peer World Map Tutorial

PHP Intl Class Peer to Peer World Map Tutorial

All the web applications in the suite of PHP intl class using web applications were capable of making a connection between …

Country Name and ISO-3166 2 letter Country Code suffixing a Locale … and … Emoji Flag

… setting our mind to an “across the board” improvement chance on top of progress up until yesterday’s PHP Intl Class Peer to Peer Serverside Tutorial.

And so, rather than change five members of “the peerage” …

  1. Sorting Words PHP code changed today this way only to reorder the external script call to be placed below the web application Javascript
  2. Language Name PHP code changed today this way only to reorder the external script call to be placed below the web application Javascript
  3. Region Name PHP code changed today this way only to reorder the external script call to be placed below the web application Javascript
  4. Currency PHP code changed today this way only to reorder the external script call to be placed below the web application Javascript
  5. Current Datetime PHP code changed today this way only to reorder the external script call to be placed below the web application Javascript

… in any major way, rather we significantly changed the one i_eg.js as per


// i_eg.js
// RJM Programming - December, 2024
// Allow for peer to peer access amongst i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php

var thisflagiso='', thisfemoji='';
var candidates="i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php";
var candidatesd=candidates;
var candidatesdesc="Current_Datetime Currency Region_Name Language_Name Sort_Words";
var candidatesdarr=candidates.replace(/\,/g,' ').split(' ');

var herel=location.search.split('locale=')[1] ? decodeURIComponent(location.search.split('locale=')[1].split('&')[0]) : '';

if (document.head.innerHTML.indexOf('/i_eg.js?') != -1) {
var qs=document.head.innerHTML.split('/i_eg.js?')[1].split('"')[0].split("'")[0].split(' ')[0].split('>')[0];
if (qs.replace(/^rand\=/g,'').indexOf('=') != -1) {
candidates=decodeURIComponent(document.head.innerHTML.split('/i_eg.js?')[1].split('=')[1].split('&')[0].split('#')[0].split('"')[0].split("'")[0]).replace(/\+/g,' ');
}
}

var candidatesarr=candidates.replace(/\,/g,' ').split(' ');

function jorflag(thiscc) {
var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var dri=['127462','127463','127464','127465','127466','127467','127468','127469','127470','127471','127472','127473','127474','127475','127476','127477','127478','127479','127480','127481','127482','127483','127484','127485','127486','127487'];
var ccsuff='', ccchar=' ', cde='';
for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
cde='.';
}
if ((document.URL.split('#')[0] + '&').indexOf(encodeURIComponent('_') + thiscc.toUpperCase() + '&') != -1 && herel != '') {
if (thisfemoji == '' && thisflagiso != '') {
ccsuff=ccsuff;
} else {
thisflagiso=thiscc.toUpperCase();
thisfemoji=ccsuff;
setTimeout(geochartit, 20000);
}
}
return ccsuff;
}

function geochartit() {
var hostelt='', bighostelt='', resthostelt='', prefb='', ctynameisnow='';
//alert('0ccsuff');
if (thisfemoji == '' && thisflagiso != '') {
thisfemoji=jorflag(thisflagiso);
}
if (thisfemoji != '' && thisflagiso != '') {
//alert('1ccsuff');
if (!document.getElementById('ageoc') && document.getElementsByTagName('h1')[0].innerHTML.indexOf(thisfemoji) != -1) {
//alert('2ccsuff');
if (document.getElementsByTagName('h1')[0].innerHTML.split(thisfemoji)[0].indexOf('<') != -1) {
prefb=document.getElementsByTagName('h1')[0].innerHTML.split(thisfemoji)[0];
ctynameisnow='%20in%20' + prefb.split('>')[eval(-1 + prefb.split('>').length)].trim() + '%20' + encodeURIComponent(thisfemoji);
//alert('ccsuff');
//bighostelt=document.getElementsByTagName('h1')[0].innerHTML.split('</')[0].split(thisfemoji)[0].split('<')[eval(-1 + document.getElementsByTagName('h1')[0].innerHTML.split('</')[0].split(thisfemoji)[0].split('<').length)];
bighostelt=document.getElementsByTagName('h1')[0].innerHTML.split(thisfemoji)[0].split('<')[eval(-1 + document.getElementsByTagName('h1')[0].innerHTML.split('</')[0].split(thisfemoji)[0].split('<').length)];
hostelt=bighostelt.split(' ')[0].split('>')[0];
resthostelt=document.getElementsByTagName('h1')[0].innerHTML.split(thisfemoji)[1].replace('</' + hostelt + '>', '').split('<')[0];
//alert('Resthostelt=' + resthostelt + ' and hostelt=' + hostelt + ' and bighostelt=' + bighostelt);
}
if (hostelt != '' && document.getElementsByTagName('h1')[0].innerHTML.split(thisfemoji)[0].indexOf('</') == -1) {
//alert('resthostelt=' + resthostelt + ' and hostelt=' + hostelt + ' and bighostelt=' + bighostelt);
if (resthostelt.trim() != '') {
document.getElementsByTagName('h1')[0].innerHTML=prefb + "</" + hostelt + "><a id=ageoc style=cursor:pointer;text-decoration:none; title=GeoChart onclick=\"window.open('//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=Where%20Locale%20" + encodeURIComponent(herel) + "%20Lives" + ctynameisnow + "&width=556&height=347&country=Country&popularity=Popularity&data=%20[~" + thisflagiso + '~,2]' + "','_blank','top=200,left=200,width=630,height=600');\">" + thisfemoji + '</a><' + bighostelt.split('>')[0] + '>' + resthostelt + '</' + hostelt + '>';
} else {
//alert(prefb + "</" + hostelt + "><a id=ageoc style=cursor:pointer;text-decoration:none; title=GeoChart onclick=\"window.open('//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=Where%20Locale%20" + encodeURIComponent(herel) + "%20Lives&width=556&height=347&country=Country&popularity=Popularity&data=%20[~" + thisflagiso + '~,2]' + "','_blank','top=100,left=100,width=600,height=600');\">" + thisfemoji + '</a>');
document.getElementsByTagName('h1')[0].innerHTML=prefb + "</" + hostelt + "><a id=ageoc style=cursor:pointer;text-decoration:none; title=GeoChart onclick=\"window.open('//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=Where%20Locale%20" + encodeURIComponent(herel) + "%20Lives" + ctynameisnow + "&width=556&height=347&country=Country&popularity=Popularity&data=%20[~" + thisflagiso + '~,2]' + "','_blank','top=200,left=200,width=630,height=600');\">" + thisfemoji + '</a>';
}
//alert('0:' + resthostelt + ' ... ' + document.getElementsByTagName('h1')[0].innerHTML);
} else {
document.getElementsByTagName('h1')[0].innerHTML=document.getElementsByTagName('h1')[0].innerHTML.replace(thisfemoji, "<a style=cursor:pointer;text-decoration:none; title=GeoChart onclick=\"window.open('//www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=Where%20Locale%20" + encodeURIComponent(herel) + "%20Lives&width=556&height=347&country=Country&popularity=Popularity&data=%20[~" + thisflagiso + '~,2]' + "','_blank','top=100,left=100,width=600,height=600');\">" + thisfemoji + '</a>');
thisfemoji='';
thisflagiso='';
//alert('1:' + document.getElementsByTagName('h1')[0].innerHTML);
}
}
}
}


function hthreesel() {
var icv=0, hthreesuffix='', curone='', curdesc='', compone=document.URL.split('?')[0].split('#')[0].split('/')[eval(-1 + document.URL.split('?')[0].split('#')[0].split('/').length)];
var hthreearr=document.getElementsByTagName('h3');

if (herel != '') {
var piso=herel.split('_')[eval(-1 + herel.split('_').length)];
piso=piso.split('-')[eval(-1 + piso.split('-').length)];
if (eval('' + piso.length) == 2 && piso == piso.toUpperCase()) {
thisflagiso=piso;
setTimeout(geochartit, 22000);
}
}


if (eval('' + hthreearr.length) > 0) {
if (hthreearr[0].outerHTML.indexOf('</select>') == -1 && candidates.trim() != '' && eval('' + candidatesarr.length) > 0) {
if ((' ' + candidatesd.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('1:' + compone + ' found at ' + candidatesdarr.indexOf(curone));
curdesc=candidatesdesc.split(' ')[candidatesdarr.indexOf(curone)].replace(/\_/g, ' ');
//alert(curdesc);
}
if (curone == '') {
if ((' ' + candidates.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('11:' + compone);
if (curone.indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
curdesc=curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase();
}
}
}

hthreesuffix='<select onchange="location.href=this.value;"><option value="' + document.URL.split('?')[0].split('#')[0] + '">Optionally select peer ' + ('to ' + curdesc).replace(/^to\ $/g, '') + ' web application below ...</option></select>';
for (icv=0; icv<candidatesarr.length; icv++) {
if (candidatesdarr.indexOf(candidatesarr[icv]) != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesdesc.split(' ')[candidatesdarr.indexOf(candidatesarr[icv])]).replace(/\_/g,' ') + '</option></select>');
} else if (candidatesarr[icv].indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase()).replace(/\_/g,' ') + '</option></select>');
} else {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + candidatesarr[icv] + '</option></select>');
}
}

if (hthreesuffix != '') {
if (curone != '' && curdesc != '') {
hthreearr[0].innerHTML+='  ' + hthreesuffix.replace('</select>', '<option value="/' + curone + '">' + curdesc + '</option></select>');
} else {
hthreearr[0].innerHTML+='  ' + hthreesuffix;
}
}
}
}
}

setTimeout(hthreesel, 2000);

… featuring an overridden function jorflag which explains our reordering of script tags we’ve talked about above.

And the benefits are that wherever you see an emoji flag in a heading tag of one of “the peerage” after a while the emoji flag can be clicked to create a popup window that shows the country relevant to the Locale involved shaded on a Google Chart Geo Chart world map.


Previous relevant PHP Intl Class Peer to Peer Serverside Tutorial is shown below.

PHP Intl Class Peer to Peer Serverside Tutorial

PHP Intl Class Peer to Peer Serverside Tutorial

Sometimes, in programming …

  • you’re stringent … especially regarding security matters, but most of the time, when we organize the programming rules, so to speak, we prefer it when …
  • you’re flexible

… and so, back with GraphViz via PHP on AlmaLinux Require Once Tutorial when we used a …

  • require_once … PHP calling paradigm (we’re not going to change it, because it is still fine) … we’re wondering now, why we didn’t use an …
  • include … paradigm, because the arrangement was optional

as per

The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.

Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

… as with the optional nature of today’s PHP include paradigm call of a new i_eg_js.php piece of PHP we’ve decided should …

Can’t “when the need arises” be contentious?

… we hear you ask. Good question! We could jump the gun, before code is properly ready using PHP glob to look for files existant under the ./i_*eg.php file specification, and match them to what we have in the i_eg.js external Javascript, adding new entries when a mismatch is found. But that is where “local knowledge” can come into play (and the other aspect to “local knowledge” here is that the suite of PHP intl class using web applications all have a file specification suiting /i_*eg.php here). Genericity has it’s limits sometimes, in other words. Take a look at what we do to time this PHP rewrites external Javascript serverside intervention safely …

<?php

<?php
// i_eg_js.php
// RJM Programming - December, 2024
// Rewrite i_eg.js as needed

$iscand=false;
$pcont='';
$jscont='';
$phplistcomp='';
$desclistcomp='';
if (file_exists('./i_eg.js')) {
$jscont=file_get_contents('./i_eg.js');
$bitsphpa=explode(' candidates="', $jscont);
$bitsdesca=explode(' candidatesdesc="', $jscont);
if (sizeof($bitsphpa) > 1 && sizeof($bitsdesca) > 1) {
foreach (glob('./i_*eg.php') as $pfile) {
$iscand=false;
$pcont='';
if (strpos(' ' . explode('"', $bitsphpa[1])[0] . ' ', ' ' . basename($pfile) . ' ') === false) {
foreach (glob('./' . basename($pfile) . '*GETME') as $ppfile) {
$iscand=true;
}

}
if ($iscand) {
$pcont=file_get_contents('./' . basename($pfile));
if (strpos($pcont, '>Show ') === false) { $iscand=false; }
}
if ($iscand) {
$jscont=str_replace(' candidates="' . explode('"', $bitsphpa[1])[0] . '"', ' candidates="' . explode('"', $bitsphpa[1])[0] . ' ' . basename($pfile) . '"', $jscont);
$jscont=str_replace(' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . '"', ' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . ' ' . str_replace(' ','_',explode('"',explode('<', explode('>Show ', $pcont)[1])[0])[0]) . '"', $jscont);
file_put_contents('./i_eg.js', $jscont);
$bitsphpa=explode(' candidates="', $jscont);
$bitsdesca=explode(' candidatesdesc="', $jscont);
}
}
}
}

?>

Yes, we share via a GETME filename suffixing set of rules here at RJM Programming, and we only do that, and upload codefiles and GETME files to the RJM Programming web server via sftp means, when we’ve tested the code.

How is this new include paradigm PHP called in each PHP web application of …

  1. Sorting Words PHP code changed today this way and changed this way yesterday
  2. Language Name PHP code changed today this way and changed this way yesterday
  3. Region Name PHP code changed today this way and changed this way yesterday
  4. Currency PHP code changed today this way and changed this way yesterday
  5. Current Datetime PHP code changed today this way and changed this way yesterday

? As simple as now having …

<?php

include "i_eg_js.php";

?>

… up near the top of the PHP code and, unlike require_once these PHP suite web applications will not fall over should they not find i_eg_js.php in their same web server folder, and meaning the use of any of “the peerage” can look for new members without constantly having to update that external Javascript list, it flowing through to that dropdown, created via that external Javascript, updated, as required, by this new PHP include paradigm intervention.

Did you know?

If we’re not introducing any new PHP members of “the peerage” today, how did we test this thinking above, to our satisfaction? Simulating the scenario on our test Apache/PHP/MySql MAMP web server is how we tested it. We went, at the local macOS command line …


cp i_eg.php i_new_eg.php

… and tested, to be satisfied that the external Javascript remained unchanged, and then went …


cp i_eg.php i_new_eg.php_GETME

… to see that the external Javascript was appropriately changed, as you can see occurring in today’s tutorial picture. When happy, we undid all these changes, ready for when a new member of “the peerage” is really added, and then we’ll test further.


Previous relevant PHP Intl Class Peer to Peer Tutorial is shown below.

PHP Intl Class Peer to Peer Tutorial

PHP Intl Class Peer to Peer Tutorial

Today we’re implementing, on top of the progress of yesterday’s PHP Intl Class Word Sorting Primer Tutorial

  • a clientside (external Javascript called by the PHP) approach to gathering this PHP intl “Internationalization” class work into a suite of peer to peer web applications so that they can easily access each other rather than worrying about any web browser address bar (or bookmark) recalling of URLs in that group (once you get one under your belt, that is) … as maybe, another day, we’ll develop …
  • a serverside (PHP require/include) approach (helping out that clientside approach more generically and scientifically)

… meaning i_eg.js external Javascript …


// i_eg.js
// RJM Programming - December, 2024
// Allow for peer to peer access amongst i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php
<>br>
var candidates="i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php";
var candidatesd=candidates;
var candidatesdesc="Current_Datetime Currency Region_Name Language_Name Sort_Words";
var candidatesdarr=candidates.replace(/\,/g,' ').split(' ');

var candidatesarr=candidates.replace(/\,/g,' ').split(' ');

function hthreesel() {
var icv=0, hthreesuffix='', curone='', curdesc='', compone=document.URL.split('?')[0].split('#')[0].split('/')[eval(-1 + document.URL.split('?')[0].split('#')[0].split('/').length)];
var hthreearr=document.getElementsByTagName('h3');
if (eval('' + hthreearr.length) > 0) {
if (hthreearr[0].outerHTML.indexOf('</select>') == -1 && candidates.trim() != '' && eval('' + candidatesarr.length) > 0) {
if ((' ' + candidatesd.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('1:' + compone + ' found at ' + candidatesdarr.indexOf(curone));
curdesc=candidatesdesc.split(' ')[candidatesdarr.indexOf(curone)].replace(/\_/g, ' ');
//alert(curdesc);
}
if (curone == '') {
if ((' ' + candidates.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('11:' + compone);
if (curone.indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
curdesc=curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase();
}
}
}


hthreesuffix='<select onchange="location.href=this.value;"><option value="' + document.URL.split('?')[0].split('#')[0] + '">Optionally select peer ' + ('to ' + curdesc).replace(/^to\ $/g, '') + ' web application below ...</option></select>';
for (icv=0; icv<candidatesarr.length; icv++) {
if (candidatesdarr.indexOf(candidatesarr[icv]) != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesdesc.split(' ')[candidatesdarr.indexOf(candidatesarr[icv])]).replace(/\_/g,' ') + '</option></select>');
} else if (candidatesarr[icv].indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase()).replace(/\_/g,' ') + '</option></select>');
} else {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + candidatesarr[icv] + '</option></select>');
}
}

if (hthreesuffix != '') {
if (curone != '' && curdesc != '') {
hthreearr[0].innerHTML+='  ' + hthreesuffix.replace('</select>', '<option value="/' + curone + '">' + curdesc + '</option></select>');
} else {
hthreearr[0].innerHTML+='  ' + hthreesuffix;
}
}
}
}
}

setTimeout(hthreesel, 2000);

… is overseeing “the peerage” …

  1. Sorting Words
  2. Language Name
  3. Region Name
  4. Currency
  5. Current Datetime

… by constructing a new dropdown means of navigating into each …


<script type=text/javascript src=/i_eg.js></script>

… of the above PHP web applications.


Previous relevant PHP Intl Class Word Sorting Primer Tutorial is shown below.

PHP Intl Class Word Sorting Primer Tutorial

PHP Intl Class Word Sorting Primer Tutorial

The PHP intl “Internationalization” class can help with an issue that has haunted me for many years. When you sort words in my English biased way, will they be sorted the same way in other languages, given alphabets and diacritics (with thanks to this excellent link regarding an example we’re defaulting to in the web application) and emojis and non-ascii characters, in various keyboard configurations, which might happen with words expressing the human condition? Luckily, the PHP intl class has

<?php

function sortit($arr, $thisloc) {
global $dias, $dia, $tabis;
$coll = collator_create( $thisloc );
//$arr = array( 'at', 'às', 'as' );
//var_export( $arr );
if (!isset($_GET['sorttype']) && !isset($_POST['sorttype'])) {
collator_sort( $coll, $arr );
} else if (isset($_GET['sorttype'])) {
if (strpos($_GET['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_GET['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_GET['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
} else if (isset($_POST['sorttype'])) {
if (strpos($_POST['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_POST['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_POST['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
}
//var_export( $arr );
for ($ij=(-1 + sizeof($arr)); $ij>=0; $ij--) {
$tabis=str_replace('<td id="sorttd">', '<td id="sorttd">' . $arr[$ij] . '<br>', $tabis);
}
echo $tabis;
}

?>

… to verify, one way or the other, and thanks to a heads up from this useful link here, further to yesterday’s PHP Intl Class Language Names Primer Tutorial.

Again, feel free to try a new “proof of concept” i_sort_eg.php Word Sorting Internationalization web application, where you can test out these concepts yourself, using your own word lists, you can enter into textarea elements.


Previous relevant PHP Intl Class Language Names Primer Tutorial is shown below.

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

You might have noticed over the last week (further to yesterday’s PHP Intl Class Region Names Primer Tutorial) or so, how useful …

Locales

… are as a data item involved with PHP intl “Internationalization” class programming work.

As an example Locale …


pt_BR

… we’ve been making quite a lot out of the “BR” ISO-3166 2 letter Country Code as the suffix of such a Locale. But what about the prefix of Locales? That prefix maps to an ISO-639 Language Code, meaning any derivable (ie. via our keyboard onkeydown and oninput logics) set of Locales could tell us (at the very least) two types of information, exemplifying the case above …

List of Countries using pt Portuguese List of Languages used in BR Brazil
pt pt_AO pt_BR pt_CH pt_CV pt_GQ pt_GW pt_LU pt_MO pt_MZ pt_PT pt_ST pt_TL es_BR pt_BR

All “code talk” above, but what about some Language Names, because you are not likely to ask down at Copacabana Beach …

Ei, cara! Você falar es?

That’s where we thank https://www.php.net/manual/en/locale.getprimarylanguage.php for the “heads up” to use code as per the followup to $lochelper and $lochelpertwo data flows to help with these Language Name determinations …

<?php

$locsel='';
$altinlang='';
$locit=user_agent();
$arrl=ResourceBundle::getLocales('');
for ($df=0; $df<sizeof($arrl); $df++) {
$endih='';
$lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
$isalt=false;
if (isset($_GET['languagecode'])) {
if (strlen($_GET['languagecode']) > 0) {
if ($lastword == $_GET['languagecode']) { $isalt=true; }
}
} else if (isset($_POST['languagecode'])) {
if (strlen($_POST['languagecode']) > 0) {
if ($lastword == $_POST['languagecode']) { $isalt=true; }
}
}
$ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
if (sizeof($ends) > 1) {
$endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if (explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0] != '') {
$inlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if ($isalt) { $altinlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0]; }
}
}
if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
//echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
$interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
//exit;
//if ($isalt) { echo $interim; exit; }
$aintm=explode('>', str_replace('</a>','',$interim))[-1 + sizeof(explode('>', str_replace('</a>','',$interim) ))];
//if ($isalt) { echo $interim . '<br>' . $aintm . '<br>' . $endih; exit; }
if (strpos($endih, ' ' . $aintm) === false) {
if ($endih != '') {
$endih.=' (' . $aintm . ')';
$inlang=' is ' . $aintm;
if ($isalt) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
} else {
$endih.=' ' . $aintm;
if ($isalt) {
//echo "Yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
}
}
}
if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
$endih.=' ' . orflag($lastword);
}
if ($endih != '') {
$endih="\t" . $endih . '';
}
if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
if ($locsel == '') {
$locsel="<select ontouchdown=ots(event); onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=(this.value); document.getElementById('justincase').src=document.URL.split('?')[0].split('#')[0] + '?ccode=' + this.value.split('_')[0].split('-')[0]; }\" id=locsel>
<option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
}
if ($locit != 'pc' && 1 == 1) {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . ' ' . $endih . "</option></select>", $locsel);
} else {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
}
}
}

?>

So, feel free to try a new “proof of concept” i_language_eg.php Language Names Internationalization web application.


Previous relevant PHP Intl Class Region Names Primer Tutorial is shown below.

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>

  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>

  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>

  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>

  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Peer to Peer Serverside Tutorial

PHP Intl Class Peer to Peer Serverside Tutorial

PHP Intl Class Peer to Peer Serverside Tutorial

Sometimes, in programming …

  • you’re stringent … especially regarding security matters, but most of the time, when we organize the programming rules, so to speak, we prefer it when …
  • you’re flexible

… and so, back with GraphViz via PHP on AlmaLinux Require Once Tutorial when we used a …

  • require_once … PHP calling paradigm (we’re not going to change it, because it is still fine) … we’re wondering now, why we didn’t use an …
  • include … paradigm, because the arrangement was optional

as per

The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.

Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

… as with the optional nature of today’s PHP include paradigm call of a new i_eg_js.php piece of PHP we’ve decided should …

Can’t “when the need arises” be contentious?

… we hear you ask. Good question! We could jump the gun, before code is properly ready using PHP glob to look for files existant under the ./i_*eg.php file specification, and match them to what we have in the i_eg.js external Javascript, adding new entries when a mismatch is found. But that is where “local knowledge” can come into play (and the other aspect to “local knowledge” here is that the suite of PHP intl class using web applications all have a file specification suiting /i_*eg.php here). Genericity has it’s limits sometimes, in other words. Take a look at what we do to time this PHP rewrites external Javascript serverside intervention safely …

<?php

<?php
// i_eg_js.php
// RJM Programming - December, 2024
// Rewrite i_eg.js as needed

$iscand=false;
$pcont='';
$jscont='';
$phplistcomp='';
$desclistcomp='';
if (file_exists('./i_eg.js')) {
$jscont=file_get_contents('./i_eg.js');
$bitsphpa=explode(' candidates="', $jscont);
$bitsdesca=explode(' candidatesdesc="', $jscont);
if (sizeof($bitsphpa) > 1 && sizeof($bitsdesca) > 1) {
foreach (glob('./i_*eg.php') as $pfile) {
$iscand=false;
$pcont='';
if (strpos(' ' . explode('"', $bitsphpa[1])[0] . ' ', ' ' . basename($pfile) . ' ') === false) {
foreach (glob('./' . basename($pfile) . '*GETME') as $ppfile) {
$iscand=true;
}

}
if ($iscand) {
$pcont=file_get_contents('./' . basename($pfile));
if (strpos($pcont, '>Show ') === false) { $iscand=false; }
}
if ($iscand) {
$jscont=str_replace(' candidates="' . explode('"', $bitsphpa[1])[0] . '"', ' candidates="' . explode('"', $bitsphpa[1])[0] . ' ' . basename($pfile) . '"', $jscont);
$jscont=str_replace(' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . '"', ' candidatesdesc="' . explode('"', $bitsdesca[1])[0] . ' ' . str_replace(' ','_',explode('"',explode('<', explode('>Show ', $pcont)[1])[0])[0]) . '"', $jscont);
file_put_contents('./i_eg.js', $jscont);
$bitsphpa=explode(' candidates="', $jscont);
$bitsdesca=explode(' candidatesdesc="', $jscont);
}
}
}
}

?>

Yes, we share via a GETME filename suffixing set of rules here at RJM Programming, and we only do that, and upload codefiles and GETME files to the RJM Programming web server via sftp means, when we’ve tested the code.

How is this new include paradigm PHP called in each PHP web application of …

  1. Sorting Words PHP code changed today this way and changed this way yesterday
  2. Language Name PHP code changed today this way and changed this way yesterday
  3. Region Name PHP code changed today this way and changed this way yesterday
  4. Currency PHP code changed today this way and changed this way yesterday
  5. Current Datetime PHP code changed today this way and changed this way yesterday

? As simple as now having …

<?php

include "i_eg_js.php";

?>

… up near the top of the PHP code and, unlike require_once these PHP suite web applications will not fall over should they not find i_eg_js.php in their same web server folder, and meaning the use of any of “the peerage” can look for new members without constantly having to update that external Javascript list, it flowing through to that dropdown, created via that external Javascript, updated, as required, by this new PHP include paradigm intervention.

Did you know?

If we’re not introducing any new PHP members of “the peerage” today, how did we test this thinking above, to our satisfaction? Simulating the scenario on our test Apache/PHP/MySql MAMP web server is how we tested it. We went, at the local macOS command line …


cp i_eg.php i_new_eg.php

… and tested, to be satisfied that the external Javascript remained unchanged, and then went …


cp i_eg.php i_new_eg.php_GETME

… to see that the external Javascript was appropriately changed, as you can see occurring in today’s tutorial picture. When happy, we undid all these changes, ready for when a new member of “the peerage” is really added, and then we’ll test further.


Previous relevant PHP Intl Class Peer to Peer Tutorial is shown below.

PHP Intl Class Peer to Peer Tutorial

PHP Intl Class Peer to Peer Tutorial

Today we’re implementing, on top of the progress of yesterday’s PHP Intl Class Word Sorting Primer Tutorial

  • a clientside (external Javascript called by the PHP) approach to gathering this PHP intl “Internationalization” class work into a suite of peer to peer web applications so that they can easily access each other rather than worrying about any web browser address bar (or bookmark) recalling of URLs in that group (once you get one under your belt, that is) … as maybe, another day, we’ll develop …
  • a serverside (PHP require/include) approach (helping out that clientside approach more generically and scientifically)

… meaning i_eg.js external Javascript …


// i_eg.js
// RJM Programming - December, 2024
// Allow for peer to peer access amongst i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php
<>br>
var candidates="i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php";
var candidatesd=candidates;
var candidatesdesc="Current_Datetime Currency Region_Name Language_Name Sort_Words";
var candidatesdarr=candidates.replace(/\,/g,' ').split(' ');

var candidatesarr=candidates.replace(/\,/g,' ').split(' ');

function hthreesel() {
var icv=0, hthreesuffix='', curone='', curdesc='', compone=document.URL.split('?')[0].split('#')[0].split('/')[eval(-1 + document.URL.split('?')[0].split('#')[0].split('/').length)];
var hthreearr=document.getElementsByTagName('h3');
if (eval('' + hthreearr.length) > 0) {
if (hthreearr[0].outerHTML.indexOf('</select>') == -1 && candidates.trim() != '' && eval('' + candidatesarr.length) > 0) {
if ((' ' + candidatesd.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('1:' + compone + ' found at ' + candidatesdarr.indexOf(curone));
curdesc=candidatesdesc.split(' ')[candidatesdarr.indexOf(curone)].replace(/\_/g, ' ');
//alert(curdesc);
}
if (curone == '') {
if ((' ' + candidates.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('11:' + compone);
if (curone.indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
curdesc=curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase();
}
}
}


hthreesuffix='<select onchange="location.href=this.value;"><option value="' + document.URL.split('?')[0].split('#')[0] + '">Optionally select peer ' + ('to ' + curdesc).replace(/^to\ $/g, '') + ' web application below ...</option></select>';
for (icv=0; icv<candidatesarr.length; icv++) {
if (candidatesdarr.indexOf(candidatesarr[icv]) != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesdesc.split(' ')[candidatesdarr.indexOf(candidatesarr[icv])]).replace(/\_/g,' ') + '</option></select>');
} else if (candidatesarr[icv].indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase()).replace(/\_/g,' ') + '</option></select>');
} else {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + candidatesarr[icv] + '</option></select>');
}
}

if (hthreesuffix != '') {
if (curone != '' && curdesc != '') {
hthreearr[0].innerHTML+='  ' + hthreesuffix.replace('</select>', '<option value="/' + curone + '">' + curdesc + '</option></select>');
} else {
hthreearr[0].innerHTML+='  ' + hthreesuffix;
}
}
}
}
}

setTimeout(hthreesel, 2000);

… is overseeing “the peerage” …

  1. Sorting Words
  2. Language Name
  3. Region Name
  4. Currency
  5. Current Datetime

… by constructing a new dropdown means of navigating into each …


<script type=text/javascript src=/i_eg.js></script>

… of the above PHP web applications.


Previous relevant PHP Intl Class Word Sorting Primer Tutorial is shown below.

PHP Intl Class Word Sorting Primer Tutorial

PHP Intl Class Word Sorting Primer Tutorial

The PHP intl “Internationalization” class can help with an issue that has haunted me for many years. When you sort words in my English biased way, will they be sorted the same way in other languages, given alphabets and diacritics (with thanks to this excellent link regarding an example we’re defaulting to in the web application) and emojis and non-ascii characters, in various keyboard configurations, which might happen with words expressing the human condition? Luckily, the PHP intl class has

<?php

function sortit($arr, $thisloc) {
global $dias, $dia, $tabis;
$coll = collator_create( $thisloc );
//$arr = array( 'at', 'às', 'as' );
//var_export( $arr );
if (!isset($_GET['sorttype']) && !isset($_POST['sorttype'])) {
collator_sort( $coll, $arr );
} else if (isset($_GET['sorttype'])) {
if (strpos($_GET['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_GET['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_GET['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
} else if (isset($_POST['sorttype'])) {
if (strpos($_POST['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_POST['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_POST['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
}
//var_export( $arr );
for ($ij=(-1 + sizeof($arr)); $ij>=0; $ij--) {
$tabis=str_replace('<td id="sorttd">', '<td id="sorttd">' . $arr[$ij] . '<br>', $tabis);
}
echo $tabis;
}

?>

… to verify, one way or the other, and thanks to a heads up from this useful link here, further to yesterday’s PHP Intl Class Language Names Primer Tutorial.

Again, feel free to try a new “proof of concept” i_sort_eg.php Word Sorting Internationalization web application, where you can test out these concepts yourself, using your own word lists, you can enter into textarea elements.


Previous relevant PHP Intl Class Language Names Primer Tutorial is shown below.

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

You might have noticed over the last week (further to yesterday’s PHP Intl Class Region Names Primer Tutorial) or so, how useful …

Locales

… are as a data item involved with PHP intl “Internationalization” class programming work.

As an example Locale …


pt_BR

… we’ve been making quite a lot out of the “BR” ISO-3166 2 letter Country Code as the suffix of such a Locale. But what about the prefix of Locales? That prefix maps to an ISO-639 Language Code, meaning any derivable (ie. via our keyboard onkeydown and oninput logics) set of Locales could tell us (at the very least) two types of information, exemplifying the case above …

List of Countries using pt Portuguese List of Languages used in BR Brazil
pt pt_AO pt_BR pt_CH pt_CV pt_GQ pt_GW pt_LU pt_MO pt_MZ pt_PT pt_ST pt_TL es_BR pt_BR

All “code talk” above, but what about some Language Names, because you are not likely to ask down at Copacabana Beach …

Ei, cara! Você falar es?

That’s where we thank https://www.php.net/manual/en/locale.getprimarylanguage.php for the “heads up” to use code as per the followup to $lochelper and $lochelpertwo data flows to help with these Language Name determinations …

<?php

$locsel='';
$altinlang='';
$locit=user_agent();
$arrl=ResourceBundle::getLocales('');
for ($df=0; $df<sizeof($arrl); $df++) {
$endih='';
$lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
$isalt=false;
if (isset($_GET['languagecode'])) {
if (strlen($_GET['languagecode']) > 0) {
if ($lastword == $_GET['languagecode']) { $isalt=true; }
}
} else if (isset($_POST['languagecode'])) {
if (strlen($_POST['languagecode']) > 0) {
if ($lastword == $_POST['languagecode']) { $isalt=true; }
}
}
$ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
if (sizeof($ends) > 1) {
$endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if (explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0] != '') {
$inlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if ($isalt) { $altinlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0]; }
}
}
if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
//echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
$interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
//exit;
//if ($isalt) { echo $interim; exit; }
$aintm=explode('>', str_replace('</a>','',$interim))[-1 + sizeof(explode('>', str_replace('</a>','',$interim) ))];
//if ($isalt) { echo $interim . '<br>' . $aintm . '<br>' . $endih; exit; }
if (strpos($endih, ' ' . $aintm) === false) {
if ($endih != '') {
$endih.=' (' . $aintm . ')';
$inlang=' is ' . $aintm;
if ($isalt) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
} else {
$endih.=' ' . $aintm;
if ($isalt) {
//echo "Yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
}
}
}
if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
$endih.=' ' . orflag($lastword);
}
if ($endih != '') {
$endih="\t" . $endih . '';
}
if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
if ($locsel == '') {
$locsel="<select ontouchdown=ots(event); onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=(this.value); document.getElementById('justincase').src=document.URL.split('?')[0].split('#')[0] + '?ccode=' + this.value.split('_')[0].split('-')[0]; }\" id=locsel>
<option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
}
if ($locit != 'pc' && 1 == 1) {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . ' ' . $endih . "</option></select>", $locsel);
} else {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
}
}
}

?>

So, feel free to try a new “proof of concept” i_language_eg.php Language Names Internationalization web application.


Previous relevant PHP Intl Class Region Names Primer Tutorial is shown below.

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>

  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>

  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>

  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>

  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Peer to Peer Tutorial

PHP Intl Class Peer to Peer Tutorial

PHP Intl Class Peer to Peer Tutorial

Today we’re implementing, on top of the progress of yesterday’s PHP Intl Class Word Sorting Primer Tutorial

  • a clientside (external Javascript called by the PHP) approach to gathering this PHP intl “Internationalization” class work into a suite of peer to peer web applications so that they can easily access each other rather than worrying about any web browser address bar (or bookmark) recalling of URLs in that group (once you get one under your belt, that is) … as maybe, another day, we’ll develop …
  • a serverside (PHP require/include) approach (helping out that clientside approach more generically and scientifically)

… meaning i_eg.js external Javascript …


// i_eg.js
// RJM Programming - December, 2024
// Allow for peer to peer access amongst i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php
<>br>
var candidates="i_eg.php i_cur_eg.php i_region_eg.php i_language_eg.php i_sort_eg.php";
var candidatesd=candidates;
var candidatesdesc="Current_Datetime Currency Region_Name Language_Name Sort_Words";
var candidatesdarr=candidates.replace(/\,/g,' ').split(' ');

var candidatesarr=candidates.replace(/\,/g,' ').split(' ');

function hthreesel() {
var icv=0, hthreesuffix='', curone='', curdesc='', compone=document.URL.split('?')[0].split('#')[0].split('/')[eval(-1 + document.URL.split('?')[0].split('#')[0].split('/').length)];
var hthreearr=document.getElementsByTagName('h3');
if (eval('' + hthreearr.length) > 0) {
if (hthreearr[0].outerHTML.indexOf('</select>') == -1 && candidates.trim() != '' && eval('' + candidatesarr.length) > 0) {
if ((' ' + candidatesd.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('1:' + compone + ' found at ' + candidatesdarr.indexOf(curone));
curdesc=candidatesdesc.split(' ')[candidatesdarr.indexOf(curone)].replace(/\_/g, ' ');
//alert(curdesc);
}
if (curone == '') {
if ((' ' + candidates.replace(/\+/g,' ') + ' ').indexOf(' ' + compone + ' ') != -1) {
curone=compone;
//alert('11:' + compone);
if (curone.indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
curdesc=curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + curone.split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase();
}
}
}


hthreesuffix='<select onchange="location.href=this.value;"><option value="' + document.URL.split('?')[0].split('#')[0] + '">Optionally select peer ' + ('to ' + curdesc).replace(/^to\ $/g, '') + ' web application below ...</option></select>';
for (icv=0; icv<candidatesarr.length; icv++) {
if (candidatesdarr.indexOf(candidatesarr[icv]) != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesdesc.split(' ')[candidatesdarr.indexOf(candidatesarr[icv])]).replace(/\_/g,' ') + '</option></select>');
} else if (candidatesarr[icv].indexOf('i_') == 0 && curone.indexOf('_eg.') != -1) {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + ('' + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(0,1).toUpperCase() + candidatesarr[icv].split('i_')[1].split('_eg.')[0].replace(/\_/g,' ').substring(1).toLowerCase()).replace(/\_/g,' ') + '</option></select>');
} else {
hthreesuffix=hthreesuffix.replace('</select>', '<option value="/' + candidatesarr[icv] + '">' + candidatesarr[icv] + '</option></select>');
}
}

if (hthreesuffix != '') {
if (curone != '' && curdesc != '') {
hthreearr[0].innerHTML+='  ' + hthreesuffix.replace('</select>', '<option value="/' + curone + '">' + curdesc + '</option></select>');
} else {
hthreearr[0].innerHTML+='  ' + hthreesuffix;
}
}
}
}
}

setTimeout(hthreesel, 2000);

… is overseeing “the peerage” …

  1. Sorting Words
  2. Language Name
  3. Region Name
  4. Currency
  5. Current Datetime

… by constructing a new dropdown means of navigating into each …


<script type=text/javascript src=/i_eg.js></script>

… of the above PHP web applications.


Previous relevant PHP Intl Class Word Sorting Primer Tutorial is shown below.

PHP Intl Class Word Sorting Primer Tutorial

PHP Intl Class Word Sorting Primer Tutorial

The PHP intl “Internationalization” class can help with an issue that has haunted me for many years. When you sort words in my English biased way, will they be sorted the same way in other languages, given alphabets and diacritics (with thanks to this excellent link regarding an example we’re defaulting to in the web application) and emojis and non-ascii characters, in various keyboard configurations, which might happen with words expressing the human condition? Luckily, the PHP intl class has

<?php

function sortit($arr, $thisloc) {
global $dias, $dia, $tabis;
$coll = collator_create( $thisloc );
//$arr = array( 'at', 'às', 'as' );
//var_export( $arr );
if (!isset($_GET['sorttype']) && !isset($_POST['sorttype'])) {
collator_sort( $coll, $arr );
} else if (isset($_GET['sorttype'])) {
if (strpos($_GET['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_GET['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_GET['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
} else if (isset($_POST['sorttype'])) {
if (strpos($_POST['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_POST['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_POST['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
}
//var_export( $arr );
for ($ij=(-1 + sizeof($arr)); $ij>=0; $ij--) {
$tabis=str_replace('<td id="sorttd">', '<td id="sorttd">' . $arr[$ij] . '<br>', $tabis);
}
echo $tabis;
}

?>

… to verify, one way or the other, and thanks to a heads up from this useful link here, further to yesterday’s PHP Intl Class Language Names Primer Tutorial.

Again, feel free to try a new “proof of concept” i_sort_eg.php Word Sorting Internationalization web application, where you can test out these concepts yourself, using your own word lists, you can enter into textarea elements.


Previous relevant PHP Intl Class Language Names Primer Tutorial is shown below.

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

You might have noticed over the last week (further to yesterday’s PHP Intl Class Region Names Primer Tutorial) or so, how useful …

Locales

… are as a data item involved with PHP intl “Internationalization” class programming work.

As an example Locale …


pt_BR

… we’ve been making quite a lot out of the “BR” ISO-3166 2 letter Country Code as the suffix of such a Locale. But what about the prefix of Locales? That prefix maps to an ISO-639 Language Code, meaning any derivable (ie. via our keyboard onkeydown and oninput logics) set of Locales could tell us (at the very least) two types of information, exemplifying the case above …

List of Countries using pt Portuguese List of Languages used in BR Brazil
pt pt_AO pt_BR pt_CH pt_CV pt_GQ pt_GW pt_LU pt_MO pt_MZ pt_PT pt_ST pt_TL es_BR pt_BR

All “code talk” above, but what about some Language Names, because you are not likely to ask down at Copacabana Beach …

Ei, cara! Você falar es?

That’s where we thank https://www.php.net/manual/en/locale.getprimarylanguage.php for the “heads up” to use code as per the followup to $lochelper and $lochelpertwo data flows to help with these Language Name determinations …

<?php

$locsel='';
$altinlang='';
$locit=user_agent();
$arrl=ResourceBundle::getLocales('');
for ($df=0; $df<sizeof($arrl); $df++) {
$endih='';
$lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
$isalt=false;
if (isset($_GET['languagecode'])) {
if (strlen($_GET['languagecode']) > 0) {
if ($lastword == $_GET['languagecode']) { $isalt=true; }
}
} else if (isset($_POST['languagecode'])) {
if (strlen($_POST['languagecode']) > 0) {
if ($lastword == $_POST['languagecode']) { $isalt=true; }
}
}
$ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
if (sizeof($ends) > 1) {
$endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if (explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0] != '') {
$inlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if ($isalt) { $altinlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0]; }
}
}
if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
//echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
$interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
//exit;
//if ($isalt) { echo $interim; exit; }
$aintm=explode('>', str_replace('</a>','',$interim))[-1 + sizeof(explode('>', str_replace('</a>','',$interim) ))];
//if ($isalt) { echo $interim . '<br>' . $aintm . '<br>' . $endih; exit; }
if (strpos($endih, ' ' . $aintm) === false) {
if ($endih != '') {
$endih.=' (' . $aintm . ')';
$inlang=' is ' . $aintm;
if ($isalt) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
} else {
$endih.=' ' . $aintm;
if ($isalt) {
//echo "Yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
}
}
}
if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
$endih.=' ' . orflag($lastword);
}
if ($endih != '') {
$endih="\t" . $endih . '';
}
if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
if ($locsel == '') {
$locsel="<select ontouchdown=ots(event); onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=(this.value); document.getElementById('justincase').src=document.URL.split('?')[0].split('#')[0] + '?ccode=' + this.value.split('_')[0].split('-')[0]; }\" id=locsel>
<option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
}
if ($locit != 'pc' && 1 == 1) {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . ' ' . $endih . "</option></select>", $locsel);
} else {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
}
}
}

?>

So, feel free to try a new “proof of concept” i_language_eg.php Language Names Internationalization web application.


Previous relevant PHP Intl Class Region Names Primer Tutorial is shown below.

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>

  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>

  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>

  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>

  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Word Sorting Primer Tutorial

PHP Intl Class Word Sorting Primer Tutorial

PHP Intl Class Word Sorting Primer Tutorial

The PHP intl “Internationalization” class can help with an issue that has haunted me for many years. When you sort words in my English biased way, will they be sorted the same way in other languages, given alphabets and diacritics (with thanks to this excellent link regarding an example we’re defaulting to in the web application) and emojis and non-ascii characters, in various keyboard configurations, which might happen with words expressing the human condition? Luckily, the PHP intl class has

<?php

function sortit($arr, $thisloc) {
global $dias, $dia, $tabis;
$coll = collator_create( $thisloc );
//$arr = array( 'at', 'às', 'as' );
//var_export( $arr );
if (!isset($_GET['sorttype']) && !isset($_POST['sorttype'])) {
collator_sort( $coll, $arr );
} else if (isset($_GET['sorttype'])) {
if (strpos($_GET['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_GET['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_GET['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
} else if (isset($_POST['sorttype'])) {
if (strpos($_POST['sorttype'], 'REGULAR') !== false) {
collator_sort( $coll, $arr, Collator::SORT_REGULAR );
} else if (strpos($_POST['sorttype'], 'NUMERIC') !== false) {
collator_sort( $coll, $arr, Collator::SORT_NUMERIC );
} else if (strpos($_POST['sorttype'], 'STRING') !== false) {
collator_sort( $coll, $arr, Collator::SORT_STRING );
} else {
collator_sort( $coll, $arr );
}
}
//var_export( $arr );
for ($ij=(-1 + sizeof($arr)); $ij>=0; $ij--) {
$tabis=str_replace('<td id="sorttd">', '<td id="sorttd">' . $arr[$ij] . '<br>', $tabis);
}
echo $tabis;
}

?>

… to verify, one way or the other, and thanks to a heads up from this useful link here, further to yesterday’s PHP Intl Class Language Names Primer Tutorial.

Again, feel free to try a new “proof of concept” i_sort_eg.php Word Sorting Internationalization web application, where you can test out these concepts yourself, using your own word lists, you can enter into textarea elements.


Previous relevant PHP Intl Class Language Names Primer Tutorial is shown below.

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

You might have noticed over the last week (further to yesterday’s PHP Intl Class Region Names Primer Tutorial) or so, how useful …

Locales

… are as a data item involved with PHP intl “Internationalization” class programming work.

As an example Locale …


pt_BR

… we’ve been making quite a lot out of the “BR” ISO-3166 2 letter Country Code as the suffix of such a Locale. But what about the prefix of Locales? That prefix maps to an ISO-639 Language Code, meaning any derivable (ie. via our keyboard onkeydown and oninput logics) set of Locales could tell us (at the very least) two types of information, exemplifying the case above …

List of Countries using pt Portuguese List of Languages used in BR Brazil
pt pt_AO pt_BR pt_CH pt_CV pt_GQ pt_GW pt_LU pt_MO pt_MZ pt_PT pt_ST pt_TL es_BR pt_BR

All “code talk” above, but what about some Language Names, because you are not likely to ask down at Copacabana Beach …

Ei, cara! Você falar es?

That’s where we thank https://www.php.net/manual/en/locale.getprimarylanguage.php for the “heads up” to use code as per the followup to $lochelper and $lochelpertwo data flows to help with these Language Name determinations …

<?php

$locsel='';
$altinlang='';
$locit=user_agent();
$arrl=ResourceBundle::getLocales('');
for ($df=0; $df<sizeof($arrl); $df++) {
$endih='';
$lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
$isalt=false;
if (isset($_GET['languagecode'])) {
if (strlen($_GET['languagecode']) > 0) {
if ($lastword == $_GET['languagecode']) { $isalt=true; }
}
} else if (isset($_POST['languagecode'])) {
if (strlen($_POST['languagecode']) > 0) {
if ($lastword == $_POST['languagecode']) { $isalt=true; }
}
}
$ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
if (sizeof($ends) > 1) {
$endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if (explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0] != '') {
$inlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if ($isalt) { $altinlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0]; }
}
}
if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
//echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
$interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
//exit;
//if ($isalt) { echo $interim; exit; }
$aintm=explode('>', str_replace('</a>','',$interim))[-1 + sizeof(explode('>', str_replace('</a>','',$interim) ))];
//if ($isalt) { echo $interim . '<br>' . $aintm . '<br>' . $endih; exit; }
if (strpos($endih, ' ' . $aintm) === false) {
if ($endih != '') {
$endih.=' (' . $aintm . ')';
$inlang=' is ' . $aintm;
if ($isalt) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
} else {
$endih.=' ' . $aintm;
if ($isalt) {
//echo "Yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
}
}
}
if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
$endih.=' ' . orflag($lastword);
}
if ($endih != '') {
$endih="\t" . $endih . '';
}
if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
if ($locsel == '') {
$locsel="<select ontouchdown=ots(event); onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=(this.value); document.getElementById('justincase').src=document.URL.split('?')[0].split('#')[0] + '?ccode=' + this.value.split('_')[0].split('-')[0]; }\" id=locsel>
<option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
}
if ($locit != 'pc' && 1 == 1) {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . ' ' . $endih . "</option></select>", $locsel);
} else {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
}
}
}

?>

So, feel free to try a new “proof of concept” i_language_eg.php Language Names Internationalization web application.


Previous relevant PHP Intl Class Region Names Primer Tutorial is shown below.

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>

  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>

  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>

  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>

  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

PHP Intl Class Language Names Primer Tutorial

You might have noticed over the last week (further to yesterday’s PHP Intl Class Region Names Primer Tutorial) or so, how useful …

Locales

… are as a data item involved with PHP intl “Internationalization” class programming work.

As an example Locale …


pt_BR

… we’ve been making quite a lot out of the “BR” ISO-3166 2 letter Country Code as the suffix of such a Locale. But what about the prefix of Locales? That prefix maps to an ISO-639 Language Code, meaning any derivable (ie. via our keyboard onkeydown and oninput logics) set of Locales could tell us (at the very least) two types of information, exemplifying the case above …

List of Countries using pt Portuguese List of Languages used in BR Brazil
pt pt_AO pt_BR pt_CH pt_CV pt_GQ pt_GW pt_LU pt_MO pt_MZ pt_PT pt_ST pt_TL es_BR pt_BR

All “code talk” above, but what about some Language Names, because you are not likely to ask down at Copacabana Beach …

Ei, cara! Você falar es?

That’s where we thank https://www.php.net/manual/en/locale.getprimarylanguage.php for the “heads up” to use code as per the followup to $lochelper and $lochelpertwo data flows to help with these Language Name determinations …

<?php

$locsel='';
$altinlang='';
$locit=user_agent();
$arrl=ResourceBundle::getLocales('');
for ($df=0; $df<sizeof($arrl); $df++) {
$endih='';
$lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
$isalt=false;
if (isset($_GET['languagecode'])) {
if (strlen($_GET['languagecode']) > 0) {
if ($lastword == $_GET['languagecode']) { $isalt=true; }
}
} else if (isset($_POST['languagecode'])) {
if (strlen($_POST['languagecode']) > 0) {
if ($lastword == $_POST['languagecode']) { $isalt=true; }
}
}
$ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
if (sizeof($ends) > 1) {
$endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if (explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0] != '') {
$inlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
if ($isalt) { $altinlang=' is ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0]; }
}
}
if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
//echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
$interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
//exit;
//if ($isalt) { echo $interim; exit; }
$aintm=explode('>', str_replace('</a>','',$interim))[-1 + sizeof(explode('>', str_replace('</a>','',$interim) ))];
//if ($isalt) { echo $interim . '<br>' . $aintm . '<br>' . $endih; exit; }
if (strpos($endih, ' ' . $aintm) === false) {
if ($endih != '') {
$endih.=' (' . $aintm . ')';
$inlang=' is ' . $aintm;
if ($isalt) {
//echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
} else {
$endih.=' ' . $aintm;
if ($isalt) {
//echo "Yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
if ($altinlang != '') {
$altinlang.=' (' . $aintm . ')';
} else {
$altinlang=' is ' . $aintm;
}
}
}
}
}
if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
$endih.=' ' . orflag($lastword);
}
if ($endih != '') {
$endih="\t" . $endih . '';
}
if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
if ($locsel == '') {
$locsel="<select ontouchdown=ots(event); onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=(this.value); document.getElementById('justincase').src=document.URL.split('?')[0].split('#')[0] + '?ccode=' + this.value.split('_')[0].split('-')[0]; }\" id=locsel>
<option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
}
if ($locit != 'pc' && 1 == 1) {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . ' ' . $endih . "</option></select>", $locsel);
} else {
$locsel=str_replace("</select>", "
<option value='" . $arrl[$df] . "' translate=\"no\" data-ontouchstart=ots(event); title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
}
}
}

?>

So, feel free to try a new “proof of concept” i_language_eg.php Language Names Internationalization web application.


Previous relevant PHP Intl Class Region Names Primer Tutorial is shown below.

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>

  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>

  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>

  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>

  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Not Categorised, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

PHP Intl Class Region Names Primer Tutorial

Apart from Ghostbusters who do you turn to when you want to know what a resident of a region calls their region?

Still, Ghostbusters, you must be pulling my leg?!

Anyway, further to yesterday’s PHP Intl Class Currency Primer Tutorial, we’ve turned to good ol’ PHP.net, as usual (when it comes to many matters PHP).

In amongst all the ISO code usage we seek when interfacing to the PHP intl “Internationalization” class, because they are definitive, even so, we feel we need to allow users to enter Country Names, as one concept, especially as Country Names have been there before any ISO codes even started. The trouble with Country Names is twofold …

  • it is not a reliable indexer, if you get my drift, because there are lots of forms, in any language you pick, for what a Country Name is
  • at least for an English representation of a Country Name we’d like consistency, and, happily, the PHP intl “Internationalization” class can provide it

… via PHP code of the ilk …

<?php

echo "<p id=pdfmt>" . locale_get_display_region(urldecode($_GET['locale']), urldecode($_GET['displaylocale'])) . "</p><br>";

?>

As you might imagine, this discovery can have mildly wide ranging implications … well, you had to be there … on …

…PHP intl class suite of web applications we’re not letting Ghostbusters anywhere near!


Previous relevant PHP Intl Class Currency Primer Tutorial is shown below.

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>
  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>
  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>
  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

PHP Intl Class Currency Primer Tutorial

We’re back with the PHP intl “Internationalization” class, today, last talked about with the recent PHP Intl Class Datetime Keyboard Events Tutorial, this time discussing …

Currency Internationalization

… topics. Again, we found the Locale data item, as with Datetimes, the main data item of interest. But, any one Country can use more than one Currency (defined by an ISO-4217 3 letter Currency Code) in this new PHP Intl using Currency web application we’ve started developing today, and on a Locale selection we choose the first such one, and leave it open to the user to be able to type in their own ISO-4217 three letter Currency Code, as required.

We got great help from https://stackoverflow.com/questions/76825595/php-format-currency-issue with codeline ideas, such as …

<?php

$formatter = new NumberFormatter(urldecode($_GET['locale']), NumberFormatter::CURRENCY);
if (isset($_GET['amount'])) {
echo "<p id=pdfmt>" . $formatter->formatCurrency(urldecode($_GET['amount']), urldecode($_GET['currency'])) . "</p><br>";
} else {
echo "<p id=pdfmt>" . $formatter->formatCurrency(76543.210, urldecode($_GET['currency'])) . "</p><br>";
}

?>

The work of Datetimes, ahead of all this, has meant it is easier to get “further down the track” for today’s “proof of concept” i_cur_eg.php PHP code start, that has keyboard event and dropdown logics all in there, and which you can try below …


Previous relevant PHP Intl Class Datetime Keyboard Events Tutorial is shown below.

PHP Intl Class Datetime Keyboard Events Tutorial

PHP Intl Class Datetime Keyboard Events Tutorial

As far as “user interaction” goes with our Current Datetime PHP web application of PHP Intl Class Datetime Google Translate Tutorial we’ve been thinking …

  • the user would be more likely to use the dropdown element selection methods … but supposing …
  • the user uses the keyboard to enter Locale and/or Timezone

… and, as of yesterday’s logic, that would have been quite unwieldy, especially regarding timezone entries.

And so, today, we’ve added keyboard onkeydown and oninput event logics to cater for several scenarios we can “shortcut” those user requirements, often down to the entry of a couple or a few characters, and from there click appropriate created links in …

<?php echo ”

var morechanges=true;
var lastwo='';
var woi=null;
var oko=null;
var nlastokn='';
var xokn='';
var xlastconto=[];
var xmorechanges=true;
var xlastwo='';
var xwoi=null;
var xoko=null;

function precval(iois) {
//okn=iois.value;
oko=iois;
lastokn=okn;
}

function xprecval(iois) {
//okn=iois.value;
xoko=iois;
xlastokn=xokn;
}

function cval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('2:' + eiois.which); }
//okn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
okn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
okn=okn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=okn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
okn='' + scs;
oko.value=okn;
lastokn=okn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
okn+=String.fromCharCode(47);
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(95);
} else {
okn+=String.fromCharCode(45);
}
if (eval('' + okn.length) > 1) { expandokn(); }
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
okn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
//document.title='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
if (eval('' + okn.length) > 1) { expandokn(); }
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
okn=okn;
} else if (1 == 3) {
okn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=1:' + okn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function xcval(eiois) {
//if (document.URL.indexOf('i0=') == -1) {
//if (eiois.which != 16) { alert('1:' + eiois.which); }
//xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
if ((eiois.which || eiois.keyCode) == 8) {
xokn='';
} else if ((eiois.which || eiois.keyCode) == 186 || (eiois.which || eiois.keyCode) == 900000016) {
xokn=xokn.replace(':','') + ':';
//document.title=okn + ' ' + (eiois.which || eiois.keyCode);
var cvi=xokn.split(':');
if (cvi.length > 1) {
var scs=0.0, factor=1.0;
for (var ij=eval(-1 + cvi.length); ij>=0; ij--) {
if (cvi[ij] == '') cvi[ij]='00';
scs+=eval(factor * eval(cvi[ij]));
factor*=60.0;
}
//alert(scs + ' ' + okn);
xokn='' + scs;
xoko.value=xokn;
xlastokn=xokn.replace(':','');
//document.title=okn + ' ' + (eiois.which || eiois.keyCode) + ' ' + oko.value;
//setTimeout(fixval,30);
}
} else if ((eiois.which || eiois.keyCode) == 191) {
if (!eiois.shiftKey) {
xokn+=String.fromCharCode(47);
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
} else if ((eiois.which || eiois.keyCode) == 189) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(95);
} else {
xokn+=String.fromCharCode(45);
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if (eiois.keyCode == 189 || (eiois.which || eiois.keyCode) >= 65 && (eiois.which || eiois.keyCode) <= 90) {
if (eiois.shiftKey) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
} else {
xokn+=String.fromCharCode(eval(32 + eval(eiois.which || eiois.keyCode)));
}
if (eval('' + xokn.length) > 1) { expandxokn(); }
//document.title='=2:' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
} else if ((eiois.which || eiois.keyCode) < 46 || (eiois.which || eiois.keyCode) > 58) {
xokn=xokn;
} else if (1 == 3) {
xokn+=String.fromCharCode(eiois.which || eiois.keyCode);
document.title+='=' + xokn + '+' + eiois.which + ' ' + eiois.keyCode + ' ... ';
}
//}
}

function expandokn() {
var iut=0, pls=[],firsttz='',tzsih='',xtzsih='',thatloc='', wds=[];
if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn != okn.toUpperCase()) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split('>' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + okn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
} else if (okn.substring(0,1) == okn.substring(0,1).toLowerCase() && okn == okn.toLowerCase()) {
xtzsih=document.getElementById('tzsel').innerHTML;
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split( value='\"' + okn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
thatloc=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0];
wds=thatloc.split('_');
if (eval('' + wds[eval(-1 + wds.length)].length) == 2 && wds[eval(-1 + wds.length)] == wds[eval(-1 + wds.length)].toUpperCase() && eval('' + wds.length) > 1) {
//alert('1:' + wds[eval(-1 + wds.length)]);
firsttz='';
if (xtzsih.indexOf(',' + wds[eval(-1 + wds.length)] + ',') != -1) {
firsttz=xtzsih.split(',' + wds[eval(-1 + wds.length)] + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
//alert('2:' + firsttz);
}
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + ' ' + jorflag(wds[eval(-1 + wds.length)]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"\"); style=cursor:pointer;text-decoration:underline;>' + thatloc + '</a>';
}
}
}

} else if (okn.substring(0,1) == okn.substring(0,1).toUpperCase() && okn == okn.toUpperCase() && eval('' + okn.length) == 2) {
document.getElementById('das').innerHTML='Country Name<br>';
pls=ctynames.split(\"'\" + okn + \"'>\");
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,0); title=' + okn + ' style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('<')[0] + ' ' + jorflag(okn) + '</a>';
}
}

tzsih=document.getElementById('tzsel').innerHTML;
if (tzsih.indexOf(',' + okn + ',') != -1) {
firsttz=tzsih.split(',' + okn + ',')[1].split('>')[1].split('<')[0].split(' ')[0];
}
document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + okn + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analr(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(okn) + '</a>';
}
}

}
}

function expandxokn() {
var iut=0, pls=[], tzsih='', thattz='';
if (xokn.substring(0,1) == xokn.substring(0,1).toUpperCase() && xokn != xokn.toUpperCase()) {
document.getElementById('das').innerHTML='TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('/' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut+=2) {
if (pls[iut].split('\"')[0].indexOf('/') == -1) {
thattz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0];
if (eval('' + tzsih.split(thattz)[1].split(' data-geo=')[1].split(',').length) > 3) {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + ' ' + jorflag(tzsih.split(thattz)[1].split(' data-geo=')[1].split(',')[3]) + '</a>';
} else {
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0].split('/' + xokn)[0] + '/' + xokn + pls[iut].split('\"')[0] + '</a>';
}
}
}
}
document.getElementById('das').innerHTML+='<br><br>Country Name<br>';
pls=ctynames.split('>' + xokn);
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analp(this,1); title=' + pls[eval(-1 + iut)].slice(-4) + ' style=cursor:pointer;text-decoration:underline;>' + xokn + pls[iut].split('<')[0] + ' ' + jorflag(pls[eval(-1 + iut)].slice(-3).substring(0,2)) + '</a>';
}
}
}
}

function analr(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
okn='';
}
}

function analq(ao,tzi) { // locale
if (ao.innerHTML.indexOf('_') != -1) {
document.getElementById('locsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('locale').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=tzi.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
okn='';
}
}

function analo(ao) { // timezone places
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
xokn='';
}
}

function analp(ao,isxokn) { // country names
var tzsih='',pls=[],iut=0, firsttz='', thattz='';
if (ao.innerHTML.indexOf('/') != -1) {
document.getElementById('tzsel').value=ao.innerHTML.split(' ')[0];
document.getElementById('timezone').value=ao.innerHTML.split(' ')[0];
document.getElementById('das').innerHTML='';
if (isxokn != 0) {
xokn='';
} else {
okn='';
}
} else {
document.getElementById('das').innerHTML+='<br><br>TimeZone Place Name<br>';
tzsih=document.getElementById('tzsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split(',' + ao.title.split(' ')[0] + ',');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
if (firsttz == '') { firsttz=pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0]; }
document.getElementById('das').innerHTML+=' <a onclick=analo(this); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

document.getElementById('das').innerHTML+='<br><br>Locale<br>';
tzsih=document.getElementById('locsel').innerHTML;
//alert(tzsih.length);
pls=tzsih.split('_' + ao.title.split(' ')[0] + '\"');
if (eval('' + pls.length) > 1) {
//alert('here');
for (iut=1; iut<pls.length; iut++) {
document.getElementById('das').innerHTML+=' <a onclick=analq(this,\"' + firsttz + '\"); style=cursor:pointer;text-decoration:underline;>' + pls[iut].split('>')[1].split('<')[0].split(' ')[0].split('+')[0] + ' ' + jorflag(ao.title.split(' ')[0]) + '</a>';
}
}

xokn='';
}
}

“; ?>

… in further changed latest draft PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Google Translate Tutorial is shown below.

PHP Intl Class Datetime Google Translate Tutorial

PHP Intl Class Datetime Google Translate Tutorial

The Internationalization improvements of yesterday’s PHP Intl Class Datetime Clock Tutorial get another boost today via the inclusion of some interfacing to the great …


Google Translate

… for those incidental translations regarding …

  • titles and headings
  • dropdown instructions

… while avoiding what might add confusion, that being any translation of user web application settings, as you might get … you being the user … that is!

But we ask first on this. And when it is the case for asking here, a useful mechanism can be the HTML input type=checkbox element which now feeds into the Javascript below …

<?php echo ”

function parhelp() {
" . $gone . "
}

function storeinnertexts() {
if (!document.getElementById('translate').checked) { return ''; }
if (!allowanyway) {
if (document.getElementById('locale').value == '') { return ''; }
if (document.getElementById('timezone').value == '') { return ''; }
}
var bcols=['yellow','yellow','white','#ffffff'];
var idcnt=0;
var seclet=['h translate=\"no\"','d','h translate=\"no\"','d','d translate=\"no\"','d','d','d'];
var inb='', ina='</span>';
var krow=0;
var itsare=['locale','loptone','timezone','toptone','calendar','calone','doneb','Clock'], thisrowis='';
var h1toform='<html><head><body>' + document.body.innerHTML.split('<form')[0] + '<br><table style=width:100%; border=2></table></body></html>';
for (var iuyt=0; iuyt<itsare.length; iuyt+=2) {
thisrowis='<tr style=background-color:' + bcols[krow] + ';></tr>';
thisrowis='<tr></tr>';
tdsuff='';
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:lightgreen;'
}
if (document.getElementById(itsare[iuyt]).value.trim() != '' || 1 == 1) {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[iuyt]).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
idcnt++;
if (bcols[krow] == '#ffffff') {
tdsuff=' style=background-color:#f0f0f0;'
}
inb='<span>';
if (eval('' + seclet[idcnt].length) > 1) {
inb='<span' + seclet[idcnt].substring(1) + '>';
}
if (itsare[eval(1 + iuyt)] == itsare[eval(1 + iuyt)].toLowerCase()) {
try {
if (document.getElementById(itsare[eval(1 + iuyt)]).innerText.trim() != '') {
//if (doseti == 1) { alert(document.getElementById(itsare[eval(1 + iuyt)]).innerText); }
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)]).innerText : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
} catch(erty) { alert(itsare[eval(1 + iuyt)]); }
} else {
if (document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value.trim() != '') {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).value : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
} else {
thisrowis=thisrowis.replace('</tr>', '<t' + seclet[idcnt].substring(0,1) + '>' + inb + (inb == '<span>' ? document.getElementById(itsare[eval(1 + iuyt)].toLowerCase()).placeholder : '') + ina + '</t' + seclet[idcnt].substring(0,1) + '></tr>');
}
}
idcnt++;
krow++;
h1toform=h1toform.replace('</table>', thisrowis + '</table>');
}
//if (doseti == 1) { alert(h1toform); }
h1toform=h1toform.replace(/Optionally\ select\ /g, '*');
h1toform=h1toform.replace(/Show\ Current\ Time/g, '@');
h1toform=h1toform.replace('RJM Programming - December, 2024', '$');
h1toform=h1toform.replace('As per (white background textboxes optional) ...', '!');
h1toform=h1toform.replace(/\<br\>/g, '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
h1toform=h1toform.replace('<span translate=\"no\"></span>', '');
//if (doseti == 1) { var tyr=prompt('' + (documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865)).length + ' ' + h1toform.replace(/\<\//g, String.fromCharCode(10) + '</'), h1toform.replace(/\<\//g, String.fromCharCode(10) + '</')); }
document.getElementById('setiif').src=documentURL.split('?')[0] + '?sra=' + encodeURIComponent(sra) + '&it=' + encodeURIComponent(h1toform) + '&rand=' + Math.floor(Math.random() * 1987865);
doseti++;
return '';
}

function setitranslate() {
if (doseti == 0) {
doseti=1;
setInterval(storeinnertexts, 2000);
}
}

“; ?>

… and the PHP …

<?php

$gtwo='';
$delthis='';
$optcnt=0;

if (isset($_GET['timezone'])) {
$_GET['timezone']=explode('%20',explode('+', $_GET['timezone'])[0])[0];
} else if (isset($_POST['timezone'])) {
$_POST['timezone']=explode('%20',explode('+', $_POST['timezone'])[0])[0];
}

function user_agent() { // thanks to https://stackoverflow.com/questions/6322112/check-if-php-page-is-accessed-from-an-ios-device/6322131
$iPod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
//file_put_contents('./public/upload/install_log/agent',$_SERVER['HTTP_USER_AGENT']);
if ($iPad||$iPhone||$iPod) {
return 'ios';
} else if ($android) {
return 'android';
} else {
return 'pc';
}
}

function server_remote_addr() {
$rma = $_SERVER['REMOTE_ADDR'];
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
// you can add different browsers with the same way ..
if (1 == 1) {
if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
$rma = '000000'.$rma;
elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
$rma = '00000'.$rma;
elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
$rma = '0000'.$rma;
elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
$rma = '000'.$rma;
elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
$rma = '00'.$rma;
elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
$rma = '0'.$rma;
}
return str_replace(':','_',str_replace('.','_',$rma));
}

if (isset($_GET['sra']) && isset($_GET['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_GET['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_GET['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
} else if (isset($_POST['sra']) && isset($_POST['it'])) {
//if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
// exec('rm -f ' . $_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html');
//}
$wopenit=false;
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html')) {
$wopenit=true;
}
$cont=str_replace('+',' ',urldecode($_POST['it']));
$cont=str_replace('*', 'Optionally select ', $cont);
$cont=str_replace('@', 'Show Current Time', $cont);
$cont=str_replace('$', 'RJM Programming - December, 2024', $cont);
$cont=str_replace('!', 'As per (white background textboxes optional) ...', $cont);
$cont=str_replace('</body>', '<style> th { background-color:yellow; } </style></body>', $cont);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/html_intl_' . str_replace('+',' ',urldecode($_POST['sra'])) . '.html', $cont);
if ($wopenit) {
echo "<html><body onload=\" parent.parhelp(); \"></body></html>";
}
exit;
}

$gone="\n setTimeout(function(){ if ((document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] != 'en') { gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=' + (document.getElementById('locale').value + document.getElementById('locale').placeholder).split('_')[0].split('-')[0] + '&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); } }, 7000); \n";

// https://www-rjmprogramming-com-au.translate.goog/PHP/GeoChart/image_chart.php?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=it&_x_tr_hl=en
if (isset($_GET['translate']) && isset($_GET['locale'])) {
if (strlen($_GET['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_GET['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_GET['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
} else if (isset($_POST['translate']) && isset($_POST['locale'])) {
if (strlen($_POST['locale']) > 0) {
$delthis=$_SERVER['DOCUMENT_ROOT'] . "/html_intl_" . server_remote_addr() . ".html";
if (explode('-',explode('_',urldecode($_POST['locale']))[0])[0] != 'en') {
$gtwo="\n setTimeout(function(){ gtwoo=window.open('https://www-rjmprogramming-com-au.translate.goog/html_intl_" . server_remote_addr() . ".html?_x_tr_sch=https&_x_tr_sl=en&_x_tr_tl=" . explode('-',explode('_',urldecode($_POST['locale']))[0])[0] . "&_x_tr_hl=en','_blank','top=200,left=' + eval(-500 + eval('' + screen.width)) + ',width=500,height=500'); }, 7000); \n";
}
}
}

?>

… to make this a possibility in a changed “fourth draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Clock Tutorial is shown below.

PHP Intl Class Datetime Clock Tutorial

PHP Intl Class Datetime Clock Tutorial

Yesterday’s PHP Intl Class Datetime Defaults Tutorial‘s PHP web application involves …

  • timezones … and, for us, whenever that happens, our eyes light up with “possibility” because …
  • “where” meets “when” … when you have timezones involved … and to our mind …
  • “where” and “when” are the best catered for “adverbs” in the I.T. wooooorrrrlllldddd

Invariably, too, the data is “full of possibility” regarding simple ideas of “internationalization” that are easy to deploy, such as …

  • emoji flags
  • Wikipedia lookups in the form of tabulated lists

And so, though our last web application is not totally disengageable from our English bias, we can help its “Internationalization Credentials” today, via …

  • emoji flag code …
    PHP
    <?php

    function orflag($incc) {
    $uretv='';
    $lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z"];
    $dri=["127462","127463","127464","127465","127466","127467","127468", "127469","127470","127471","127472","127473","127474","127475", "127476","127477","127478","127479","127480","127481", "127482","127483","127484","127485","127486","127487"];
    for ($jjm=0; $jjm<strlen($incc); $jjm++) {
    for ($jm=0; $jm<sizeof($lri); $jm++) {
    if (strtoupper(substr(substr($incc,$jjm),0,1)) == $lri[$jm]) {
    $uretv.='&#' . $dri[$jm] . ";";
    }
    }
    }
    return $uretv;
    }

    ?>
    Javascript
    <?php echo ”

    function jorflag(thiscc) {
    var lri='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var dri=['127462','127463','127464','127465','127466','127467','127468', '127469','127470','127471','127472','127473','127474', '127475','127476','127477','127478','127479','127480', '127481','127482','127483','127484','127485','127486','127487'];
    var ccsuff='', ccchar=' ', cde='';
    for (var iccsuff=0; iccsuff<thiscc.length; iccsuff++) {
    ccchar=thiscc.substring(iccsuff, eval(1 + eval('' + iccsuff))).toUpperCase();
    ccsuff+=String.fromCodePoint(dri[eval('' + lri.indexOf(ccchar))]); //'&#' + dri[eval('' + lri.indexOf(ccchar))] + ';';
    cde='.';
    }
    return ccsuff;
    }

    “; ?>
  • new clock functionality (using an Internationalization emoji usage regarding an SVG based button background image) and known timezone reasons to tabulate …
    <?php

    $tabp='';
    $tabs='';
    if (isset($_GET['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_GET['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    } else if (isset($_POST['timezone'])) {
    $tabp='<table style=width:100%;><tr><td style=vertical-align:top;>';
    $tabs='</td><td style=vertical-align:top;width:50%;><iframe src="/HTMLCSS/colour_wheel.html?mode=' . $_POST['timezone'] . '" style=width:100%;height:800px;></iframe></td></tr></table>';
    }
    $revealp='';
    $reveals='';
    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</text></svg>";

    if (isset($_GET['clock']) || isset($_POST['clock'])) {
    $revealp='<details title="Form you can use to display different time or different clock"><summary title="Form you can use to display different time or different clock"></summary>' . $tabp;
    $reveals=$tabs . '</details>';
    $clockcss="\n #pdfmt { border-radius: 50px; } \n";
    } else {
    $revealp=$tabp;
    $reveals=$tabs;
    }

    ?>
  • document.body onload emoji flag application (via Javascript) …
    <?php echo ”

    function onlit() {
    txils=parent.document.getElementById('tzsel').innerHTML.split(' value=\"' + thistz + '\"');
    if (eval('' + txils.length) > 1) {
    isov=txils[1].split('>')[0].split(',')[3];
    cnb='';
    if (ctynames.indexOf(\" value='\" + isov + \"'>\") != -1) {
    cnb=' in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('tzsel').title='Default is a Timezone in ' + ctynames.split(\" value='\" + isov + \"'>\")[1].split('<')[0];
    document.getElementById('myh1').innerHTML+=' for ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[1].replace(/\_/g,' ') + ' ' + (thistz + '/').replace(thistz.split('/')[0] + '/', '').split('/')[0].replace(/\_/g,' ').trim().replace('Argentina','');
    document.getElementById('myh1').innerHTML+=cnb + ' ' + jorflag(isov);
    }
    }
    }

    “; ?>
  • clock button styling …
    <?php

    $clockcss='';
    $clocksvg="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewport='0 0 100 100' style='font-family:Verdana;font-size:10px;'><text y='50%'>\\0023f0</svg>";

    ?>
    <?php echo ”

    <style>
    " . $clockcss . "
    input[type=\"text\"] { width: 250px; }
    #clock { border-radius: 50px; color:pink; text-shadow:-1px 1px 1px yellow; background-image: url('" . str_replace("'",'"',$clocksvg) . "'); }
    </style>

    “; ?>

  • clock recursive style functionality via an iframe onload event paradigm (with function clockif below) …
    <?php echo ”

    var documentURL=document.URL;
    var repcnt=0, cnb='', isov='', txils=[];
    var thistz=(location.search.split('timezone=')[1] ? (decodeURIComponent(location.search.split('timezone=')[1].split('&')[0]) + '') : '');

    function clockif(iois) {
    if (iois.src.indexOf('About_Us.') == -1) {
    repcnt++;
    setTimeout(function(){ iois.src=iois.src.split('&rand=')[0] + '&rand=' + repcnt; }, 1000);
    var aconto = (iois.contentWindow || iois.contentDocument);
    if (aconto != null) {
    if (aconto.document) { aconto = aconto.document; }
    if (aconto.body != null) {
    if (aconto.getElementById('pdfmt') && parent.document.getElementById('pdfmt')) {
    parent.document.getElementById('pdfmt').innerHTML=aconto.getElementById('pdfmt').innerHTML;
    if (repcnt == 1) {
    parent.document.getElementById('pdfmt').style.border='5px dotted pink';
    parent.document.getElementById('pdfmt').style.padding='5 5 5 5';
    if (eval('' + txils.length) > 1) {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/') + txils[1].split('>')[0] + cnb;
    } else {
    parent.document.getElementById('pdfmt').title='Timestamp for ' + documentURL.split('?')[1].split('&cl')[0].replace(/\&/g,' ').replace(/\=/g,' ').replace(/\%2F/g,'/').replace(/\%2f/g,'/');
    }
    }
    }
    }
    }
    }
    }

    “; ?>
    … called into play via document.body onload Javascript …
    <?php echo ”

    <body onload="onlit(); if (documentURL.indexOf('clock=') != -1) { setTimeout(function(){ document.getElementById('justincase').src=documentURL=documentURL.replace('clock=','cloNOWAYck=') + '&rand=' + repcnt; }, 1000); } ">

    “; ?>
    … along with a new form submit button choice …
    <?php echo ”

    <input style=background-color:#f0f0f0; title=Clock type=submit id=clock name=clock value=Clock></input>

    “; ?>
  • dropdown option (subelement) emoji flag title …
    Locale
    <?php

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    $endih='';
    $lastword=explode('_',$arrl[$df])[-1 + sizeof(explode('_',$arrl[$df]))];
    $ends=explode("['" . explode('-',explode('_',$arrl[$df])[0])[0] . '-', $lochelper);
    if (sizeof($ends) > 1) {
    $endih.=' ' . explode("'", explode("['", $ends[0])[-1 + sizeof(explode("['", $ends[0]))])[0];
    }
    if (strpos($lochelpertwo, '>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>') !== false) {
    //echo "yes " . explode('-',explode('_',$arrl[$df])[0])[0] . "\n<br>";
    //echo substr(explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0], -250,250);
    $interim=explode('</a>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0])[-1 + sizeof(explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0]))])[0]; //)[-1 + sizeof(explode('>', explode('</td>', explode('<tr', explode('>' . explode('-',explode('_',$arrl[$df])[0])[0] . '</a>', $lochelpertwo)[0];
    //exit;
    $aintm=explode('>', $interim)[-1 + sizeof(explode('>', $interim))];
    if (strpos($endih, ' ' . $aintm) === false) {
    if ($endih != '') {
    $endih.=' (' . $aintm . ')';
    } else {
    $endih.=' ' . $aintm;
    }
    }
    }
    if ($lastword == strtoupper($lastword) && strlen($lastword) == 2) {
    $endih.=' ' . orflag($lastword);
    }
    if ($endih != '') {
    $endih="\t" . $endih . '';
    }

    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "' translate=\"no\" title=\"" . $endih . "\">" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
    TimeZone
    <?php

    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    $yls=explode(" data-geo='", $yourtzlist);
    for ($iy=(-1 + sizeof($yls)); $iy>=1; $iy--) {
    if (sizeof(explode(',', $yls[$iy])) > 3) {
    $icp=explode(',', $yls[$iy])[3];
    //echo $icp;
    if ($icp == strtoupper($icp) && strlen($icp) == 2 && strpos($icp, '?') === false) {
    //echo $icp . ' data-geo="' . $yls[$iy] . ' becomes ' . ' title="' . orflag($icp) . '" data-geo="' . $yls[$iy];
    //exit;
    $yourtzlist=str_replace(" data-geo='" . $yls[$iy], ' title=' . "'" . orflag($icp) . "'" . " data-geo='" . $yls[$iy], $yourtzlist);
    }
    }
    }


    ?>

… in a changed “third draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Defaults Tutorial is shown below.

PHP Intl Class Datetime Defaults Tutorial

PHP Intl Class Datetime Defaults Tutorial

Onto the recent PHP Intl Class Datetime Tutorial start to a PHP Current Datetime Intl Using Internationalization web application we see a way forward improving …

  • default Locale and TimeZone presented …
    Locale
    <?php

    $defloc=Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);

    ?>
    Timezone
    <?php

    $deficc=explode('_', str_replace('_posix','',$defloc))[-1 + sizeof(explode('_', str_replace('_posix','',$defloc)))];
    $yourtzlist="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('timezone').value=this.value; }\" id=tzsel><option id=\"toptone\" value=''>Optionally select a TimeZone below ...</option><option value='Africa/Abidjan' data-geo='5.31666,-4.03334,GMT,CI,+0'>Africa/Abidjan</option><option value='Africa/Accra' data-geo='5.55,-0.21667,GMT,GH,+0'>Africa/Accra</option><option value='Africa/Addis_Ababa' data-geo='9.03333,38.7,EAT,ET,+3'>Africa/Addis_Ababa</option><option value='Africa/Algiers' data-geo='36.78333,3.05,CET,DZ,+1'>Africa/Algiers</option> ... blah ... blah ... blah ... </select>";

    if (strpos($yourtzlist, ',' . $deficc . ',') !== false) {
    $ourtz=explode('<', explode('>', explode(',' . $deficc . ',', $yourtzlist)[1])[1])[0];
    } else {
    $ourtz="''"; //date.timezone; // ($_SERVER['TZ'] ?? (file_get_contents('/etc/timezone') ?: file_get_contents('/etc/localtime')))
    }

    ?>
  • add accompanying dropdown ways to select values from a list of what is available on Locale and TimeZone (as above) and Calendar …
    <?php

    $calsel='';
    if (1 == 1) {
    $bundle=new ResourceBundle('','ICUDATA');
    $cnames=[];
    $calendars=$bundle->get('calendar');
    foreach ($calendars as $n=>$v) {
    if ($calsel == '') {
    $calsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('calendar').value=this.value; }\" id=calsel><option value=''>Optionally select a Calendar system below ...</option></select>";
    }
    $calsel=str_replace("</select>", "<option value='" . $n . "'>" . $n . "</option></select>", $calsel);
    $cnames[]=$n;
    }
    }

    $locsel='';
    $arrl=ResourceBundle::getLocales('');
    for ($df=0; $df<sizeof($arrl); $df++) {
    if (strpos(($arrl[$df] . '_'), '_') !== false) { //} && strpos($arrl[$df], '0') === false) {
    if ($locsel == '') {
    $locsel="<select onchange=\"if (this.value.trim().length != 0) { document.getElementById('locale').value=tzdef(this.value); }\" id=locsel><option id=\"loptone\" value=''>Optionally select a Locale below ...</option></select>";
    }
    $locsel=str_replace("</select>", "<option value='" . $arrl[$df] . "'>" . $arrl[$df] . "</option></select>", $locsel);
    }
    }

    ?>
  • change input type=text placeholder reflect any previously selected Locale and TimeZone and/or Calendar …
    <?php echo ”

    echo "<h1>Show Current Time</h1><br><h3>RJM Programming - December, 2024</h3><br><h4>As per (white background textboxes optional) ...</h4><br><br><form method=GET onsubmit=\"if (document.getElementById('calendar').value.trim() != '') { document.getElementById('calendar').name='calendar'; } if (document.getElementById('locale').value.trim() == '' || document.getElementById('timezone').value.trim() == '') { return false; } return true;\" action=\"./i_eg.php\">
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=locale name=locale placeholder=" . (isset($_GET['locale']) ? urldecode($_GET['locale']) : (isset($_POST['locale']) ? urldecode($_POST['locale']) : $defloc)) . " value='' title=Locale></input> " . $locsel . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:yellow; id=timezone name=timezone placeholder=" . (isset($_GET['timezone']) ? urldecode($_GET['timezone']) : (isset($_POST['timezone']) ? urldecode($_POST['timezone']) : $ourtz)) . " value='' title=TimeZone></input> " . $yourtzlist . "
    <br><input type=text ondblclick=this.value=this.placeholder; style=background-color:white; id=calendar placeholder=" . (isset($_GET['calendar']) ? urldecode($_GET['calendar']) : (isset($_POST['calendar']) ? urldecode($_POST['calendar']) : "gregorian")) . " value='' title=Calendar></input> " . $calsel . "
    <br><br><input style=background-color:lightgreen; type=submit value=Display></input>
    </form>
    ";

    “; ?>

… and regarding Locale selections take the opportunity to gather up to the top of Locale and TimeZone dropdowns any options relevant to any Locale first selected …

<?php echo ”

<scri" . "pt type=text/javascript>
var ctynames=\"" . str_replace("\n","",$ctynames) . "\";
var canmakenothing=false, firstloc='';

function tzdef(inloc) { // wrapper around Locale dropdown selected value
var inicc=inloc.replace(/\-/g,'_').split('_')[eval(-1 + inloc.replace(/\-/g,'_').split('_').length)];
var jnicc=inicc;
var newtstuff='', newlstuff='', newts=0, newls=0, tvalis='';
if (ctynames.indexOf(\" value='\" + inicc + \"'>\") != -1) {
jnicc=ctynames.split(\" value='\" + inicc + \"'>\")[1].split('<')[0];
}
if (document.getElementById('timezone').value == '' && inicc.trim() != '' && inicc == inicc.toUpperCase() && eval('' + inicc.length) == 2) {
var tzoh=document.getElementById('tzsel').innerHTML;
var aftertopt=document.getElementById('toptone').outerHTML;
var tzloh=document.getElementById('locsel').innerHTML;
var afterlopt=document.getElementById('loptone').outerHTML;
var tzs=tzoh.split(',' + inicc + ',');
if (eval('' + tzs.length) > 1) {
//document.getElementById('timezone').value=tzs[1].split('>')[1].split('<')[0];
tvalis=tzs[1].split('>')[1].split('<')[0];
newtstuff+='<option value=\"' + tvalis + '\">' + tvalis + '</option>';
for (newts=1; newts<eval('' + tzs.length); newts++) {
if (tzs[newts].split('>')[1].split('<')[0] != tvalis) {
newtstuff+='<option value=\"' + tzs[newts].split('>')[1].split('<')[0] + '\">' + tzs[newts].split('>')[1].split('<')[0] + '</option>';
}
}
tzs=tzloh.split('_' + inicc + '\"');
if (eval('' + tzs.length) > 1) {
newlstuff+='<option value=\"' + inloc + '\">' + inloc + '</option>';
for (newls=1; newls<eval('' + tzs.length); newls++) {
if (tzs[newls].split('>')[1].split('<')[0] != inloc) {
newlstuff+='<option value=\"' + tzs[newls].split('>')[1].split('<')[0] + '\">' + tzs[newls].split('>')[1].split('<')[0] + '</option>';
}
}
}
}
if (tzoh.indexOf(aftertopt) != -1 && newtstuff != '') {
document.getElementById('tzsel').innerHTML=aftertopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Time', ' ' + jnicc + ' Time') + newtstuff + aftertopt + tzoh.split(aftertopt)[1];
}
if (tzloh.indexOf(afterlopt) != -1 && newlstuff != '') {
document.getElementById('locsel').innerHTML=afterlopt.replace(' id=', ' data-id=').replace(' value=\"', ' value=\" ').replace(' a Locale', ' ' + jnicc + ' Locale') + newlstuff + afterlopt + tzloh.split(afterlopt)[1];
}
if (tvalis != '') { document.getElementById('timezone').value=tvalis; }
document.getElementById('locsel').value=inloc;
firstloc=inicc;
canmakenothing=true;
}
if (document.getElementById('tzsel').value == ' ' && canmakenothing) {
if (inicc != firstloc) {
document.getElementById('tzsel').value='';
}
}
return inloc.replace(/\-/g,'_');
}
</scr" . "ipt>

“; ?>

… containing an ISO-3166 2 letter Country Code at it’s end, mentioning that country’s name in that first option of the TimeZone dropdown, so that some users will see a Country Name in the mix, adding to relatability, perhaps.

We feel this considerably improves the User Experience using a changed “second draft” PHP code offering here, as a PHP web application, you can also try below.


Previous relevant PHP Intl Class Datetime Tutorial is shown below.

PHP Intl Class Datetime Tutorial

PHP Intl Class Datetime Tutorial

We’re back revisiting the PHP intl “Internationalization” class mentioned in “the AlmaLinux install feeling” PHP Mbstring Multibyte String and Intl Class Tutorial

Reading a bit, we cottoned onto three data items being central to Datetime PHP intl usage being …

  1. locale
  2. timezone
  3. calendar … optional

… and, so, we’re starting our “learning curve” (we got great help from this excellent website developing …

<?php

if (isset($_GET['locale']) && isset($_GET['timezone']) && isset($_GET['calendar'])) {
$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
urldecode($_GET['locale']) . '@calendar=' . urldecode($_GET['calendar']),
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
urldecode($_GET['timezone']),
IntlDateFormatter::TRADITIONAL);

echo '<p>' . $IntlDateFormatter->format($DateTime) . '</p><br><br>';
}

?>

…) in today’s “first draft” “proof of concept” offering here, as a PHP web application, you can also try below …


Previous relevant PHP Mbstring Multibyte String and Intl Class Tutorial is shown below.

PHP Mbstring Multibyte String and Intl Class Tutorial

PHP Mbstring Multibyte String and Intl Class Tutorial

We’re revisiting the PHP Mbstring Multibyte String Primer Tutorial of the past to see where we stand now with PHP 8 and …

  • mbstring “Multibyte String” extension … and …
  • intl “Internationalization Functions” extension

… 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 tweaked mbstring_test.php “old way” live run and “new way” live run via the writing of a couple of “proof of concepts” …


Previous relevant PHP Mbstring Multibyte String Primer Tutorial is shown below.

PHP Mbstring Multibyte String Primer Tutorial

PHP Mbstring Multibyte String Primer Tutorial

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 …

<?php phpinfo(); ?>

… and if, in doing this, you find a reference to the “mbstring” 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 UTF-8 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.

We followed a lot of the advice of the very useful link (thanks) to create some PHP called …

… where we show what we always suspected but were too shy to ask, and didn’t flesh it out before … doh! … you can’t split a Chinese phrase’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.

So we take the Chinese phrase 火车票 (which translates into English as “Train tickets” … and we thank Google Translate for help with all this) and use PHP mbstring’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’d probably guess would happen), and then translate all these into English using Google Translate, as an intellectual exercise.

If this exercise makes you …

  • a) fall on the floor laughing
  • b) hit a gong with a huge hammer
  • c) cook up some deep fried dumplings
  • d) put the left chopstick in the right ear and the right chopstick in the left ear (please ask for adult supervision) … translation: do not do this
  • e) while reading you sweep the cat under the rug (no animals were harmed in the making of this blog posting)

… then we’re here to tell you that you need to take a Bex and have a lie down.

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 live run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Textbox Form Filling Niceties Primer Tutorial

Textbox Form Filling Niceties Primer Tutorial

Some of us spend a lot of time, online, filling out forms. Do you like doing it? Is it very much “a mixed bag”? Personally, we think, yes, very much so, it is a mixed bag.

We think, on this occasion, but definitely not always, “intervening” (away from HTML form and input type=text textbox defaults) can help.

Before we outline what we discovered, why not try our online (“we won’t be taking much more than a minute of your time” … and haven’t we all heard that one!)

So, what did you think?

If you are like me, yes, (and thanks to https://stackoverflow.com/questions/13284323/how-can-i-stop-auto-capitalization-in-a-html-text-input-field-on-an-android-sams for the “heads up” here) a …

Mix of autocorrect=”off” autocapitalize=”off” text-transform:lowercase; text-transform:uppercase;

… as far as a tailored to a form’s predicted user answer content goes, it can make the process that little bit happier. Maybe you’re a programmer eyeing this up?

… in the “proof of concept” first draft Form Filling Speed Test web application we’re presenting today. Happy “online” form filling!

Did you know?

With today’s work we concentrated on HTML input type=text “textboxes” but there is the HTML input type=number element type you can use for (that last) numerical textbox. Personally, we sometimes see this helping, but we’re not convinced that it works best for every “numerical occasion”, and we’re not convinced that all users having one foisted on them appreciate it’s talents, over a “textbox consistently applied” (perhaps involving a pattern attribute) approach?!

If this was interesting you may be interested in this too.

Posted in eLearning, Event-Driven Programming, Tutorials | Tagged , , , , , , , , , , , , , , , | Leave a comment