Caitlin-havener Posted February 24, 2011 Share Posted February 24, 2011 I have this bit here:if (!preg_match("/($guessletter)/",$text))What I want the condition to say is if the 'guessletter' is NOT in the $text, perform operation. How do I do this? Link to comment Share on other sites More sharing options...
[dx] Posted February 24, 2011 Share Posted February 24, 2011 if (!(preg_match("/($guessletter)/",$text))) { Try. Link to comment Share on other sites More sharing options...
Caitlin-havener Posted February 24, 2011 Author Share Posted February 24, 2011 It appears to work, thanks!Any idea how to get the following to work: //Hangman image if (isset($bad_guess_print[1])) print"<img src='images/1.jpg' alt=''/>"; else if (isset($bad_guess_print[2])) print"<img src='images/2.jpg' alt=''/>"; else if (isset($bad_guess_print[3])) print"<img src='images/3.jpg' alt=''/>"; else if (isset($bad_guess_print[4])) print"<img src='images/4.jpg' alt=''/>"; else if (isset($bad_guess_print[5])) print"<img src='images/5.jpg' alt=''/>"; else if (isset($bad_guess_print[6])) print"<img src='images/6.jpg' alt=''/>"; else if (isset($bad_guess_print[7])) print"<img src='images/7.jpg' alt=''/>"; else if (isset($bad_guess_print[8])) print"<img src='images/8.jpg' alt=''/>"; else if (isset($bad_guess_print[9])) print"<img src='images/9.jpg' alt=''/>"; else if (isset($bad_guess_print[10])) print"<img src='images/10.jpg' alt=''/>"; else{} It is supposed to display an image if the cell of that array has a value in it. Come to think of it, I'm going to only want one of these images to show at a time (the greater number cell). Any ideas? Link to comment Share on other sites More sharing options...
Caitlin-havener Posted February 24, 2011 Author Share Posted February 24, 2011 MEH actually I guess the code isn't working for the preg_match Link to comment Share on other sites More sharing options...
Synook Posted February 24, 2011 Share Posted February 24, 2011 Your original code snippet and Haris's are exactly the same. If you show us the rest of that code we could help you figure out the problem.For your second question, why not just: echo "<img src=\"images/" . count($bad_guess_print) - 1 . ".jpg\" alt=\"\" />"; Link to comment Share on other sites More sharing options...
Caitlin-havener Posted February 24, 2011 Author Share Posted February 24, 2011 Your original code snippet and Haris's are exactly the same. If you show us the rest of that code we could help you figure out the problem.For your second question, why not just:<?php // woffer02.php error_reporting(0); session_start(); if (empty($_SESSION)) { //Initialize session variables $_SESSION['bad_guess_index'] = 0; $_SESSION['guess_array'] = array(); $_SESSION['index']=0; $_SESSION['turn']="GOLD"; //GOOD}?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="style_project_two.css" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> <style type="text/css"> .mtable td { width:50px; } </style> </head> <body> <div id="wrap"> <div id="header"><h1>Caitlin's Jeopardy</h1></div> <div id="right"> <form method="post"> <?php #textloader: function textloader($whatfile) { if (!file_exists($whatfile)) { print "Sorry, can't find $whatfile."; exit; } else { $textarray=file($whatfile); return $textarray; } }# textloader #display: Draws the Jeopardy table function display($visible, $letters) { $letterlength=count($letters); print "<table class='mtable' border=1><tr>"; for ($i=1; $i<$letterlength; $i++) { //print "i=$i,visible=".$visible[$i]."<br />"; if ($letters[$i]==' ') print "</tr></table><br/> <table class='mtable'><tr>"; else if ($visible[$i]) { print "<td><center>".$letters[$i]."</center></td>"; } else print "<td> </td>"; } print "</tr></table>"; } #drawinputscreen: Asks for input. function drawinputscreen($guesses) { print "<input type='text' name='guessletter'>"; print "Guess a letter. You have $guesses guesses left."; print "<input type='submit' name='action' value='GUESS'>"; print "<input type='submit' name='action' value='REVEAL'>"; print "<input type='submit' name='action' value='NEXT PHRASE'>"; //print "<input type='submit' name='action' value='END SESSION'> (then refresh)"; } ######## MAIN PROGRAM ########## print"<img src='images/vanna.jpg' alt=''/>"; //initialize variables $array= textloader("clichefile.txt"); $index=$_SESSION['index']; $letters = array(); $act=isset($_POST['action']) ? $_POST['action'] : ''; $text = array_key_exists($index, $array) ? $array[$index] : "There are no more phrases left."; $txtarr=($text); //Print whos turn $turn_print=$_SESSION['turn']; print"<div id='team'>It is $turn_print team's turn.</div>"; //print "$text"; //Assign each letter to letters array and uppercase it for ($i=0; $i<strlen($text);$i++) { $letters[$i+1]=strtoupper($text[$i]); } $letterlength=count($letters); $visible=isset($_SESSION['visible']) ? $_SESSION['visible']: array(); $guesses=isset($_SESSION['guesses']) ? $_SESSION['guesses']: ''; /* if(!$act){ for ($i=1; $i<=$letterlength; $i++) $visible[$i]=0; $guesses=16; } */ switch ($act) { case '': for ($i=1; $i<=$letterlength; $i++) $visible[$i]=0; //If there are no more phrases left if ($text=="There are no more phrases left."){ for ($i=1; $i<=$letterlength; $i++) $visible[$i]=1; } else{ for ($i=1; $i<=$letterlength; $i++) $visible[$i]=0; } $guesses=16; break; case "GUESS": $guessletter=strtoupper($_POST['guessletter']); // a-> A, etc. uppercase for ($i=1; $i<=$letterlength; $i++) { $ll=$letters[$i]; if ($guessletter==$letters[$i]) { $visible[$i]=1; } } //var_dump($_SESSION); //WHOS TURN?? $turn=$_SESSION['turn']; if ($turn=="GOLD"){ $_SESSION['turn']="BLACK"; } else if($turn=="BLACK"){ $_SESSION['turn']="GOLD"; } #End whos turn $guesses=$guesses-1; //IF LETTER IS NOWHERE TO BE FOUND. $guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: ''; if (!(preg_match("/($guessletter)/",$text))){ print "<p class='right_side'>That letter was no where to be found.</p>"; $_SESSION['guess_array'][$guess_index] = $guessletter; $_SESSION['bad_guess_index'] += 1; $guess_index=isset($_SESSION['bad_guess_index']) ? $_SESSION['bad_guess_index']: ''; //print"$guess_index <br/>"; } $bad_guess_print=isset($_SESSION['guess_array']) ? $_SESSION['guess_array']: array(); $guess_index=$_SESSION['bad_guess_index']; print"<div id='bad_guesses'><p>Bad Guesses</p> <br />"; //print"$guess_index <br/>"; //foreach($guess_index as $value){ for($i=0; $i<$guess_index; $i++){ print"<p class='right_side' style='color:red'>$bad_guess_print[$i] </p>"; } print"</div>"; break; case "NEXT PHRASE": $_SESSION['index']+= 1; unset($_SESSION['bad_guess_index']); unset($_SESSION['guess_array']); unset($_SESSION['visible']); unset($_SESSION['letters']); unset($_SESSION['guesses']); $guesses=16; for ($i=1; $i<=$letterlength; $i++) $visible[$i]=0; break; case "REVEAL": for ($i=1; $i<=$letterlength; $i++) $visible[$i]=1; break; case "END SESSION": session_destroy(); break; } //RUN OUT OF GUESSES if ($guesses==0){ print"<div id='lose'>You lose! Click NEXT PHRASE.</div>"; } else if ($guesses==1){ print"<div id='last'>This is your last guess!!!</div>"; } print"</div>"; print"<div id='left'>"; display($visible,$letters); drawinputscreen($guesses); print"</div>"; $_SESSION['visible']=$visible; $_SESSION['guesses']=$guesses; ?><tt>Note: Guesses counter was working fine on local Apache server and the whole guess_array was printing as well. The correctly guessed letters were accumulating on the screen as they were guessed- as you see they are going away when another correct letter is guessed.They all are not working after being uploaded. Please let me know if you see the issues. Thanks. </tt></div></form></body></html> Link to comment Share on other sites More sharing options...
birbal Posted February 24, 2011 Share Posted February 24, 2011 make it "/$guessletter/i" would work i thinkthere is lot of case jugling . i think there is a case issue in your regexp Link to comment Share on other sites More sharing options...
Caitlin-havener Posted February 24, 2011 Author Share Posted February 24, 2011 YAYY that worked! If you have the time, could you have a looksie at my other post http://w3schools.invisionzone.com/index.php?showtopic=36601 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.