On top of yesterday’s PHP City Guess Country Game Data Extension Tutorial today’s progress zeroes in on some aesthetic ideas …
- add country flag emojis (for interest sake) …
<?php
function getih($indefe) {
$lri="ABCDEFGHIJKLMNOPQRSTUVWXYZ^$";
$zri="abcdefghijklmnopqrstuvwxyz^$0123456789#@!~`";
$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","127988","917631"];
$sri=["917601","917602","917603","917604","917605","917606","917607","917608","917609","917610","917611","917612","917613","917614","917615","917616","917617","917618","917619","917620","917621","917622","917623","917624","917625","917626","127988","917631","30","31","32","33","34","35","36","37","38","39","127937","65039","8205","127752","127987"];
$thiscc=$indefe;
$ccsuff='';
$ccchar=' ';
$cde='';
for ($iccsuff=0; $iccsuff<strlen($thiscc); $iccsuff++) {
$ccchar=substr($thiscc, $iccsuff, (1 + $iccsuff));
if (strtolower($ccchar) == $ccchar) {
$ccsuff.=$cde . $sri[strpos($lri,$ccchar)] . ';'; //'' + dri[eval('' + lri.indexOf(ccchar))] + ';';
} else {
$ccsuff.=$cde . $dri[strpos($lri,$ccchar)] . ';'; //'' + dri[eval('' + lri.indexOf(ccchar))] + ';';
}
}
return $ccsuff;
}
foreach (glob("*cities*.xml") as $filename) {
$fchunk=file_get_contents($filename);
$bits=explode("<City>", $fchunk);
for ($i=1; $i<sizeof($bits); $i++) {
$thistwobits=explode("<", $bits[$i]);
$citiesarr[sizeof($citiesarr)]=$thistwobits[0];
$thistwobits=explode("<Country>", $bits[-1 + $i]);
$thosetwobits=explode("<", $thistwobits[-1 + sizeof($thistwobits)]);
$countriesarr[sizeof($countriesarr)]=$thosetwobits[0];
if (strpos($ctyisotwo, ">" . $thosetwobits[0]) !== false) {
$countriesisotwo[sizeof($countriesisotwo)]=getih(trim(explode("<",explode('">', explode(">" . $thosetwobits[0],$ctyisotwo)[1])[1])[0]));
} else {
$countriesisotwo[sizeof($countriesisotwo)]=trim(" ");
}
if (!strstr($uniquecountries, "," . urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)]) . ",")) {
$uniquecountries .= urlencode($thosetwobits[0] . $countriesisotwo[-1 + sizeof($countriesisotwo)]) . ",";
}
$countriesarr[-1 + sizeof($countriesarr)].=$countriesisotwo[-1 + sizeof($countriesisotwo)];
$countriesisotwo[-1 + sizeof($countriesisotwo)]='';
}
}
?>
… using another “data extension” via the incredibly useful link where a Country name can be linked to an ISO 2 character country code (integral to forming those country flag emojis in the PHP code above) - increase readability by increasing font and element sizes
See the changed city_guess.php City Guess Country game in action.
Previous relevant PHP City Guess Country Game Data Extension Tutorial is shown below.
We had occasion to revisit the “City Guess Country Game” web application of PHP City Guess Country Game Sharing Tutorial and were dismayed at the absence of “Belgium” on the country list. We looked into the workings of the web application and found that it based its City and Country dropdowns based on the contents of Webservices XML files (who we would like to thank profusely).
How to start seeing Belgium, even though we write this on a Wednesday? We think we could either …
- start accessing the Webservices Belgium XML file (but, sadly, if you’ve tried that last link, you can see why not) … or …
- “data extend” (not talk about file extensions) the Capitals and Countries data sets of Country via Capital Placeholder Quiz Game Tutorial and that way, guarantee at least one city entry per country
… and yes, we opted for the latter. And yes, we recognize there will be a lopsided number of cities linking to the XML data countries. True enough, but playing the quiz, this does not detract from the interest of the quiz in our opinion. And it feels that much more interesting and challenging seeing a full list of country (answer) options for any city (question) ask, in our opinion.
But the proof is in the “user pudding” and perhaps you will find the changed city_guess.php City Guess Country game more or less challenging than the one lacking Belgium (perhaps because it’s Wednesday?)
Previous relevant PHP City Guess Country Game Sharing Tutorial is shown below.
We mentioned how much thought was needed for our revamped Nimh game to involve an Inline HTML Form Email, and thereby be spurning any Javascript “smarts” already involved, so as to both …
- collaborate and share and involve more than one game player … as well as …
- seeing the graphics of that game there in the body section of the email
… and so, rather than jumping straight into Nimh (ouch! … got burnt!) we are picking …
- a simple PHP game …
- currently involving lots of Javascript “smarts” in its workings …
- not yet involving any Inline HTML Form Email functionality
… and work towards collaborating and sharing via those means. The verdict? Yes, even for “small games” like the changed city_guess.php City Guess Country game (you can read the background to, with PHP City Guess Country Game Primer Tutorial), it is no doddle to think “no Javascript”. It is an exercise that helps you appreciate the power and usefulness of client-side Javascript in web applications. The upside is an improvement of your appreciation of how to pare something down to those smaller “navigatable” HTML form snippets to break a concept into collaborative and sharable parts.
Two new HTML form elements become involved, to make this happen …
- the HTML form method=POST action=’//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php’ … to navigate to Inline HTML Form Email creating PHP helper web application …
<form target=iemail style=display:none; action='//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php' method=POST>
<input type=hidden name=inline value=''></input>
<input type=hidden name=emailto id=emailto value=''></input>
<input type=hidden name=subject id=subject value='City Guess Country Game'></input>
<textarea style=display:none; name=htmlis id=htmlis value=''></textarea>
<input type=submit style=display:none; id=contact value=Email></input>
</form>
… filling in emailto (Email To) and htmlis (Inline HTML Form Email content) in a named HTML iframe element, so as not to have to navigate away from the web page …
<iframe name=iemail src=//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php style=display:none;></iframe>
- the HTML form method=GET action=’https://www.rjmprogramming.com.au/Games/CityGuessCountry/city_guess.php’ shell …
<form target=_top id=cgcform action='https://www.rjmprogramming.com.au/Games/CityGuessCountry/city_guess.php' method=GET>
</form>
… encasing existant HTML City and Country elements
… and on returning to “web browser land” from “email client land” the emailee’s answers contribute to the PHP logic …
$egoes="0";
$escore="0";
$emdef="";
if (isset($_GET['thiscity']) && isset($_GET['ucountry']) && isset($_GET['eanswer'])) {
if ($_GET['ucountry'] == $_GET['eanswer']) {
$egoes="1 Well done! " . str_replace("+"," ",urldecode($_GET['thiscity'])) . " is indeed in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . ".";
$escore="1";
} else {
$egoes="1 Sorry, <a title='Google image search' style=cursor:pointer;text-decoration:underline; onclick=woit(this.innerHTML);>" . str_replace("+"," ",urldecode($_GET['thiscity'])) . "</a> is in " . str_replace("+"," ",urldecode($_GET['eanswer'])) . " but is not in " . str_replace("+"," ",urldecode($_GET['ucountry'])) . ".";
}
if (isset($_GET['emailfrom'])) {
$emdef=str_replace("+"," ",urldecode($_GET['emailfrom']));
}
}
… informing of the user of the “Check” (submit button) of their email dropdown selected Country answer for the City presented to them.
We found that second method=GET was the means by which macOS Mail app and Webmail means of emailing were both supported.
Previous relevant PHP City Guess Country Game Primer Tutorial is shown below.
There is no end to the variety of web applications you can do by seeing what free information is out there, but please don’t disrepect the sources of that information. The source for our information today is the excellent XML files created at Webservices … so … thanks.
Today’s game is deceptively simple but quite dynamic, in the sense that we set aside a web server directory for our game today that we have called “City Guess Country Game” and whatever subset of XML files you have from http://www.webservicex.net/new/Home/Index are dynamically read to be the source of information. Here, for the next level up of dynamism you’d involve an RSS feed perhaps, but, today, we just talk about using what we statically have “plonked” in our directory set aside for the game. The word “plonked” always makes me associate with the ever useful PHP method called glob … yes … glob … and so it is here, because that “globbing” definitely goes on. What you will perhaps be disappointed with today is that we don’t use PHP XML native functionality to process the XML data, and please know we recommend trying these approaches as you see fit, but we find the PHP explode method relatively easy to deploy for scenarios like this where the data form is so predictable, and simple.
Deceptively simple games can sometimes be the best, and find that that interest, or not, relates to what we are interested in ourselves … for me that, in particular, is atlases, geography, the “where” of life … so today’s game interests me as much as it will bore others (no doubt).
We show you PHP source code you could call city_guess.php and a live run link as well.
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.