{"id":48050,"date":"2020-02-21T03:01:18","date_gmt":"2020-02-20T17:01:18","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=48050"},"modified":"2020-02-21T05:53:51","modified_gmt":"2020-02-20T19:53:51","slug":"php-city-guess-country-game-sharing-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-city-guess-country-game-sharing-tutorial\/","title":{"rendered":"PHP City Guess Country Game Sharing Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP City Guess Country Game Sharing Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess_email.jpg\" title=\"PHP City Guess Country Game Sharing Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">PHP City Guess Country Game Sharing Tutorial<\/p><\/div>\n<p>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 &#8220;smarts&#8221; already involved, so as to both &#8230;<\/p>\n<ul>\n<li>collaborate and share and involve more than one game player &#8230; as well as &#8230;<\/li>\n<li>seeing the graphics of that game there in the body section of the email<\/li>\n<\/ul>\n<p> &#8230; and so, rather than jumping straight into Nimh (ouch! &#8230; got burnt!) we are picking &#8230;<\/p>\n<ul>\n<li>a simple PHP game &#8230;<\/li>\n<li>currently involving lots of Javascript &#8220;smarts&#8221; in its workings &#8230;<\/p>\n<li>not yet involving any Inline HTML Form Email functionality<\/li>\n<\/ul>\n<p> &#8230; and work towards collaborating and sharing via those means.  The verdict?  Yes, even for &#8220;small games&#8221; like <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php-GETME\" title=\"city_guess.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php-GETME\" title=\"city_guess.php\">city_guess.php<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php\" title=\"Click picture\">City Guess Country game<\/a> (you can read the background to, with <a title='PHP City Guess Country Game Primer Tutorial' href='#phpcgcgpt'>PHP City Guess Country Game Primer Tutorial<\/a>), it is no doddle to think &#8220;no Javascript&#8221;.  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 &#8220;navigatable&#8221; HTML form snippets to break a concept into collaborative and sharable parts.<\/p>\n<p>Two new HTML form elements become involved, to make this happen &#8230;<\/p>\n<ol>\n<li>the HTML form method=POST <font size=1>action=&#8217;\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php&#8217;<\/font> &#8230; to navigate to Inline HTML Form Email creating PHP helper web application &#8230;<br \/>\n<code><br \/>\n&lt;form target=iemail style=display:none; action='\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php' method=POST&gt;<br \/>\n &lt;input type=hidden name=inline value=''&gt;&lt;\/input&gt;<br \/>\n &lt;input type=hidden name=emailto id=emailto value=''&gt;&lt;\/input&gt;<br \/>\n &lt;input type=hidden name=subject id=subject value='City Guess Country Game'&gt;&lt;\/input&gt;<br \/>\n &lt;textarea style=display:none; name=htmlis id=htmlis value=''&gt;&lt;\/textarea&gt;<br \/>\n &lt;input type=submit style=display:none; id=contact value=Email&gt;&lt;\/input&gt;<br \/>\n &lt;\/form&gt;<br \/>\n<\/code><br \/>\n &#8230; filling in <i>emailto<\/i> (Email To) and <i>htmlis<\/i> (Inline HTML Form Email content) in a named HTML iframe element, so as not to have to navigate away from the web page &#8230;<br \/>\n<code><br \/>\n&lt;iframe name=iemail src=\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php style=display:none;&gt;&lt;\/iframe&gt;<br \/>\n<\/code>\n<\/li>\n<li>the HTML form method=GET <font size=1>action=&#8217;https:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php&#8217;<\/font> shell &#8230;<br \/>\n<code><br \/>\n&lt;form target=_top id=cgcform action='https:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php' method=GET&gt;<br \/>\n&lt;\/form&gt;<br \/>\n<\/code><br \/>\n &#8230; encasing existant HTML City and Country elements\n<\/li>\n<\/ol>\n<p> &#8230; and on returning to &#8220;web browser land&#8221; from &#8220;email client land&#8221; the emailee&#8217;s answers contribute to the PHP logic &#8230;<\/p>\n<p><code><br \/>\n$egoes=\"0\";<br \/>\n$escore=\"0\";<br \/>\n$emdef=\"\";<br \/>\n<br \/>\nif (isset($_GET['thiscity']) && isset($_GET['ucountry']) && isset($_GET['eanswer'])) {<br \/>\n  if ($_GET['ucountry'] == $_GET['eanswer']) {<br \/>\n    $egoes=\"1  Well done!  \" . str_replace(\"+\",\" \",urldecode($_GET['thiscity'])) . \" is indeed in \" . str_replace(\"+\",\" \",urldecode($_GET['eanswer'])) . \".\";<br \/>\n    $escore=\"1\";<br \/>\n  } else {<br \/>\n    $egoes=\"1  Sorry, &lt;a title='Google image search' style=cursor:pointer;text-decoration:underline; onclick=woit(this.innerHTML);&gt;\" . str_replace(\"+\",\" \",urldecode($_GET['thiscity'])) . \"&lt;\/a&gt; is in \" . str_replace(\"+\",\" \",urldecode($_GET['eanswer'])) . \" but is not in \" . str_replace(\"+\",\" \",urldecode($_GET['ucountry'])) . \".\";<br \/>\n  }<br \/>\n  if (isset($_GET['emailfrom'])) {<br \/>\n    $emdef=str_replace(\"+\",\" \",urldecode($_GET['emailfrom']));<br \/>\n  }<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; informing of the user of the &#8220;Check&#8221; (submit button) of their email dropdown selected Country answer for the City presented to them.<\/p>\n<p>We found that second method=GET was the means by which macOS Mail app and Webmail means of emailing were both supported.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/php-city-guess-country-game-sharing-tutorial\/'>PHP City Guess Country Game Sharing Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpcgcgpt'>Previous relevant <a target=_blank title='PHP City Guess Country Game Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-city-guess-country-game-primer-tutorial\/'>PHP City Guess Country Game Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP City Guess Country Game Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.jpg\" title=\"PHP City Guess Country Game Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">PHP City Guess Country Game Primer Tutorial<\/p><\/div>\n<p>There is no end to the variety of web applications you can do by seeing what free information is out there, but please don&#8217;t disrepect the sources of that information.  The source for our information today is the excellent XML files created at <a target=_blank title='http:\/\/www.webserviceX.NET' href='http:\/\/www.webserviceX.NET'>Webservices<\/a> &#8230; so &#8230; thanks.<\/p>\n<p>Today&#8217;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 &#8220;City Guess Country Game&#8221; and whatever subset of XML files you have from <a target=_blank title='http:\/\/www.webserviceX.NET' href='http:\/\/www.webserviceX.NET'>http:\/\/www.webservicex.net\/new\/Home\/Index<\/a> are dynamically read to be the source of information.  Here, for the next level up of dynamism you&#8217;d involve an RSS feed perhaps, but, today, we just talk about using what we statically have &#8220;plonked&#8221; in our directory set aside for the game.  The word &#8220;plonked&#8221; always makes me associate with the ever useful PHP method called <a target=_blank title='PHP glob method information' href='http:\/\/php.net\/manual\/en\/function.glob.php'><i>glob<\/i><\/a> &#8230; yes &#8230; glob &#8230; and so it is here, because that &#8220;globbing&#8221; definitely goes on.  What you will perhaps be disappointed with today is that we don&#8217;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 <a target=_blank href='http:\/\/php.net\/manual\/en\/function.explode.php' title='PHP explode method information'><i>explode<\/i><\/a> method relatively easy to deploy for scenarios like this where the data form is so predictable, and simple.<\/p>\n<p>Deceptively simple games can sometimes be the best, and find that that interest, or not, relates to what we are interested in ourselves &#8230; for me that, in particular, is atlases, geography, the &#8220;where&#8221; of life &#8230; so today&#8217;s game interests me as much as it will bore others (no doubt).<\/p>\n<p>We show you PHP source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php_GETME\" title=\"city_guess.php\">city_guess.php<\/a> and a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Games\/CityGuessCountry\/city_guess.php\" title='Click picture'>live run<\/a> link as well.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d19522' onclick='var dv=document.getElementById(\"d19522\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/games\/\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d19522' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d48050' onclick='var dv=document.getElementById(\"d48050\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/email\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d48050' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;smarts&#8221; already involved, so as to both &#8230; collaborate and share and involve more than &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-city-guess-country-game-sharing-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,15,37],"tags":[3232,2081,380,382,452,476,477,576,2487,652,932,997,1022,1319],"class_list":["post-48050","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-games","category-tutorials","tag-city","tag-country","tag-email","tag-email-form","tag-form","tag-game","tag-games-2","tag-html","tag-inline","tag-javascript","tag-php","tag-programming","tag-quiz","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48050"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=48050"}],"version-history":[{"count":11,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48050\/revisions"}],"predecessor-version":[{"id":48072,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/48050\/revisions\/48072"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=48050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=48050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=48050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}