rehat Posted June 8, 2008 Share Posted June 8, 2008 Most of my programming experience is with C++ and I am new with scripting languages. I'm having a hard time understanding how statements are executed in PHP. For example the code below is from a book I'm reading: <html> <head><title>Temperature Conversion</title></head> <body> <?php $fahr = $_GET['fahrenheit']; if (is_null($fahr)) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET"> Fahrenheit temperature: <input type="text" name="fahrenheit" /> <br /> <input type="submit" name="Convert to Celsius!" /> </form> <?php } else { $celsius = ($fahr - 32) * 5/9; printf("%.2fF is %.2fC", $fahr, $celsius); } ?> </body> </html> What I would like to know is how the script is processed. So I understand the first if statement prints out the form in html if the value of $fahr is null, but I'm kind of lost as to how the else statement gets executed. Any help would be great thanks. Link to comment https://forums.phpfreaks.com/topic/109309-need-help-understanding-php/ Share on other sites More sharing options...
rarebit Posted June 8, 2008 Share Posted June 8, 2008 when the page is called (after the form is submitted) it will have an url something like "index.phtml?fahrenheit=99", the parser then makes a global super variable 'fahrenheit' in the $_GET array... If this exists then it will be different and effect the logic... The page is like a script or program which accepts args, the output depends upon the input... Link to comment https://forums.phpfreaks.com/topic/109309-need-help-understanding-php/#findComment-560713 Share on other sites More sharing options...
rehat Posted June 8, 2008 Author Share Posted June 8, 2008 Oh, I didn't relize the submit button reloads the page. Thanks Link to comment https://forums.phpfreaks.com/topic/109309-need-help-understanding-php/#findComment-560732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.