Jump to content

Need help understanding PHP


rehat

Recommended Posts

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

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.