This article mainly introduces the PHP implementation of the word guessing games, interested in the reference of friends, hope to help you.
Just copy it locally and run it.
<?phpsession_start (); Header ("content-type:text/html;charset=utf-"); $url = ' http://' $_server[' http_host ']$_ server[' php_self '];function Get_word () {$wordtext = "redistribution and use of source and binary forms, with or without modif Ication, is permitted provided that the following conditions is met:redistributions of source code must retain the above Copyright notice, this list of conditions and the following disclaimer redistributions in binary form must reproduce the Above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials P Rovided with the distribution neither the name of the YII software LLC or the names of its contributors could be used to endors E or promote products derived from the software without specific prior written permission this software was provided by TH E COPYRIGHT Holders and CONTRIBUTORS as is and any EXPRESS OR implied warranties, including, but not LIMITED to, the Impli ED warranties of merchantability and FITness for A particular PURPOSE is disclaimed in NO EVENT shall the COPYRIGHT OWNER OR CONTRIBUTORS is liable for any DIRE CT, INDIRECT, incidental, special, exemplary, OR consequential damages (including, but not LIMITED to, procurement of SUBS Titute GOODS OR SERVICES; LOSS of Use, DATA, OR profits; or business interruption) however caused and on any theory of liability, WHETHER in contract, STRICT liability, OR TORT (I ncluding negligence OR OTHERWISE) arising in any-out-of-the---the-software, even IF advised of the possibility O F SUCH DAMAGE "; $words =preg_split ("/[\s,]+/", $wordtext);d o{$i =rand (, Count ($words)-); $word =strtoupper ($words [$i]);} while (strlen ($word) < | |!ctype_alpha ($WORD)); return $word;} function Guess ($word) {return Str_repeat (' _ ', strlen ($word));} function output ($word) {$str = '; for ($i =; $i <strlen ($word); $i + +) {$str = $word [$i] "";} return RTrim ($STR);} if (Isset ($_get[' op ')) && $_get[' op ']== ' start ') {$k =$_get[' k '];$_session[' num ']= $k; exit;} if (Isset ($_get[' RestaRT ']) && $_get[' restart ']==) {session_unset (); Header ("Location: $url"); exit;} if (!isset ($_session[' word ')) {$word =get_word (); $_session[' word ']= $word;} else{$word =$_session[' word '];} $guessguess _word=guess ($word), if (Isset ($_get[' op ')) && $_get[' op ']== ' Ajax ') {$k =$_get[' k ']; $re = "; Isset ($_session[' already ')) {$_session[' already ']=guess ($_session[' word ']);} if (!isset ($_session[' count ')) {$_session[' count ']=;} if (Strpos ($_session[' word ', $k)!==false) {for ($i =; $i <strlen ($_session[' word]), $i + +) {if ($_session[' word '] [$i ]!= $k) {$re = ' _ ';} else{$re =$_session[' word ' [$i];}} for ($i =; $i <strlen ($_session[' word "), $i + +) {if ($_session[' already '] [$i]== ' _ ') {$_session[' already '] [$i]= $re [$ I];}}} else{$_session[' count ']+=;} $return =output ($_session[' already ')), if ($_session[' count '] <= $_session[' num ')} {if ($_session[' already ']==$_ session[' word ']) {$return = "|";} else{$return = "|";}} else{$return = "|";} echo $return; exit;}? ><script>function Ajax (recvtype) {var aj=new Object (); ajrecvtype=recvtyPE? Recvtypetouppercase (): ' HTML '; ajtargeturl= '; ajsendstring= '; ajresulthandle=null;ajcreatexmlhttprequest= function () {var xmlHttp = false;if (windowxmlhttprequest) {xmlHttp = new XMLHttpRequest ();} else if (windowactivexobject) {try{xmlhttp = new ActiveXObject ("Msxmlxmlhttp");} catch (Error) {try{xmlhttp = new ActiveXObject ("Microsoftxmlhttp");} catch (Error) {xmlHttp = false;}}} return xmlHttp;} Ajxmlhttprequest=ajcreatexmlhttprequest (); Ajprocesshandle=function () {if (ajxmlhttprequestreadystate = =) {if ( Ajxmlhttprequeststatus = =) {if (ajrecvtype== "HTML") {Ajresulthandle (ajxmlhttprequestresponsetext);} else if (ajrecvtype== "XML") {Ajresulthandle (ajxmlhttprequestresponsexml);}}} Ajget=function (TargetUrl, Resulthandle) {ajtargeturl=targeturl;if (resulthandle!=null) { Ajxmlhttprequestonreadystatechange=ajprocesshandle;ajresulthandle=resulthandle;} if (windowxmlhttprequest) {Ajxmlhttprequestopen ("get", Ajtargeturl); Ajxmlhttprequestsend (null);} Else{ajxmlhttprequestopen ("Get", Ajtargeturl, true); ajxmlhttprequestsend();}} return AJ; </script><script>var ajax=ajax (); function Select (v) {Documentgetelementbyid (v) styledisplay= ' none '; Ajaxget ("guessphp?op=ajax&k=" +v, function (r) {var t=rsplit ("|"); Documentgetelementbyid (' word ') innerhtml=t[];if (t[] = =) {Documentgetelementbyid (' select ') styledisplay= ' none '; Documentgetelementbyid (' result ') innerhtml= ' success ';} else if (t[] = =) {Documentgetelementbyid (' select ') styledisplay= ' None ';d ocumentgetelementbyid (' result ') innerhtml= ' Failed ';}}); function Check (v) {ajaxget ("guessphp?op=start&k=" +v, function (r) {windowlocationhref= "<?php echo $url;? > ";});} </script><?phpif (!isset ($_session[' num ')) {echo ' <input type= "Radio" onclick= "Check ();"/> Easy: Wrong <br/> '; Echo ' <input type= ' radio ' onclick= ' Check (); "/> Normal:wrong <br/> '; Echo ' <input type = "Radio" onclick= "Check ();"/> Hard:wrong <br/> ';} Else{//echo $word; echo "Can guess the most wrong" $_session[' num '] "times", echo "<br/>"; echo "<p id= ' word ' >"; Echo Output ($guess_word), Echo ' </p> ', echo ' <br/> ', echo ' <p id= ' select ' > '; for ($i =ord (' A '); $i <=ord (' Z '); + + $i) { echo "\ n", $letter =CHR ($i), echo ' <span id= ' $letter ' "style=" display: "><a href=" javascript:void (); "onclick= "Select (\ ' $letter ' \ ');" > ' $letter ' </a></span> ';} Echo ' </p> '; Echo ' <br/> '; Echo ' <br/> '; Echo ' <p id= ' result ' ></p> '; Echo ' <br/> '; echo ' <br/> '; Echo ' <a href= ' $url '? restart= ' > Restart </a> ';}? >
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
How to implement PHP code processing pictures
PHP Recursive algorithm detailed
PHP Extension Multi-threading