garyblackpool Posted September 29, 2009 Share Posted September 29, 2009 Hi i having problem with this code its not bringing the correct greating. it is just showing the "new roll" greating after a turn has been taken. I have checked and it seems to be right thanks x <?printGreeting();printDice();printForm();function printGreeting(){ global $guess, $numPetals; if (empty($guess)){ print"<h3>Welcome to Petals Around the Rose</h3>"; } else if ($guess == $numPetals){ print"<h3> You Got it</h3>"; }else{ print <<<HERE <h3>From your last try </h3> you guessed: $guess</br> -and the correct answer was: $numberPetals around the rose</br> HERE;}//end if }//end greating function printDice(){ global $numPetals; print "<h3>New Roll:</h3>"; $numPetals = 0; $die1 = rand(1,6); $die2 = rand(1,6); $die3 = rand(1,6); $die4 = rand(1,6); $die5 = rand(1,6); $die6 = rand(1,6); showDie($die1); showDie($die2); showDie($die3); showDie($die4); showDie($die5); showDie($die6); print "<br>"; calcNumPetals($die1); calcNumPetals($die2); calcNumPetals($die3); calcNumPetals($die4); calcNumPetals($die5); calcNumPetals($die6); } //end dice function showDie($value){ print <<<HERE <img src="dice$value.jpeg" height=100 width=100HERE;} // end show Diefunction calcNumPetals($value){ global $numPetals; switch ($value) { case 3: $numPetals +=2; break; case 5: $numPetals += 4; break;} //end switch} //end switchfunction printForm(){ global $numPetals; print<<<HERE <h3> How many petals around the rose?</h3> <form method = "post"> <input type = "text" name = "guess" value= "0"> <input type ="hidden" name="numPetals" value="$numPetals"> </br> <input type ="submit"> </form> </br> <a href = "petalHelp.html" target ="helpPage"> give me a hint!</a>HERE;} //end print form?> Link to comment Share on other sites More sharing options...
chibineku Posted September 29, 2009 Share Posted September 29, 2009 What does <<<Here ... HERE;mean? Link to comment Share on other sites More sharing options...
jlhaslip Posted September 29, 2009 Share Posted September 29, 2009 What does <<<Here ... HERE;mean?google heredoc syntax Link to comment Share on other sites More sharing options...
chibineku Posted September 29, 2009 Share Posted September 29, 2009 Ah, I see. What's the advantage? Link to comment Share on other sites More sharing options...
garyblackpool Posted September 29, 2009 Author Share Posted September 29, 2009 I feel a little bit clever i have got it. I was missing $guess = $_POST["guess"];The code which i was using did not have that show i am wondering if the book is php4. Thanks Link to comment Share on other sites More sharing options...
garyblackpool Posted September 29, 2009 Author Share Posted September 29, 2009 I think heredocs saves you from printing each line. Link to comment Share on other sites More sharing options...
chibineku Posted September 29, 2009 Share Posted September 29, 2009 Well, why not just echo since you're not using printf? Link to comment Share on other sites More sharing options...
dsonesuk Posted September 29, 2009 Share Posted September 29, 2009 if you want to include large amount of html code, and if you enjoy echoing each html code line, escaping every quote, entering newline, so it does not look like one big lump of joined html, well you just go ahead.But! i will stick with the heredoc method. Link to comment Share on other sites More sharing options...
chibineku Posted September 29, 2009 Share Posted September 29, 2009 I routinely echo multi line blocks, I just use single quotes to start and end and since I have a habit of using double quotes everywhere else, I never need to escape anything *shrugs* Link to comment Share on other sites More sharing options...
justsomeguy Posted September 29, 2009 Share Posted September 29, 2009 Heredoc syntax is for outputting large blocks of text where you want to do variable replacement. Single quotes do not do variable replacement. The nowdoc syntax is similar to a heredoc except it does not replace variables.heredoc : double-quote :: nowdoc : single-quoteMaybe you haven't found a need for heredocs or nowdocs at this point, but eventually you will. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.