<?php
  if (isset($_GET['source'])) {
        highlight_file($_SERVER['SCRIPT_FILENAME']);
        exit;
  }
?>
<html>
<head>
<title>Basic PHP Example</title>
    
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="theme-color" content="#B5C7DD" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../css/reset.css">
        <link rel="stylesheet" href="../css/mandy.css">

<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
</head>
<body>
    
<p class="pad-top">    
    
<?php   # need this to be able to view source in the below anchor tag
  $urlPath=dirname($_SERVER['SCRIPT_URL']).'/'; 
  $labsPath=$urlPath.'labs/'; 
?>     

    <a href="<?=$urlPath?>index.php?source" target="labs">Lab 3 Source code</a>

</p>    
    
    
<?php   
    //  Part I
    //  defining constants  
    
    # expanded string old way
define ("Greeter", "Welcome, Whoever !");

    # float new way
const phi = 1.61803398875;
    
    # integer new way
const year = 2018;
       
    //  Part II
    //  declaring variables
       
    # integer
       $_3 = 3;
         
    # boolean       
       $true = True;
         
    # float aka double
       $lead = 1.2;
         
    # string       
       $user = "Dear Grader";
       
    # string (var) that contains another string (variable)      
       $Greeter = "Welcome, $user !";   
       
    //  Kieth's  variables
$intvar = 2;
$floatvar = 4.4;
$string = "1 is the loneliest number";
$thisvar = $intvar + $string;   # server: it's a non well formed numeric value and considers it to be an integer variable
$that = $floatvar - $string;    # server: it's a non well formed numeric value and considers it to be a float variable
$other = $intvar * $floatvar;   # 2*4.4 = 8.8, which is a float
$what = "$intvar";              # $intvar being in double quotes becomes an expanded string, which is the content of $what   
       
    //  printing the getttype variables
echo "<h4>My Variables</h4> <p>";    # insert html elements - will be re-used     
       
    # output the type of the variable $_3      
print 'the type of the variable $_3 is: '.gettype($_3);       
    
echo "<br>";    # line break for readability - will be re-used
       
# output the type of the variable $true      
print 'the type of the variable $true is: '.gettype($true); 

       echo "<br>";    
       
# output the type of the variable $lead      
print 'the type of the variable $lead is: '.gettype($lead); 

       echo "<br>";    

# output the type of the variable $user      
print 'the type of the variable $user is: '.gettype($user); 

       echo "<br>";

# output the type of the variable $Greeter  
print 'the type of the variable $Greeter is: '.gettype($Greeter); 

       echo "</p>";    # closing My Variables Paragraph       
       
       
echo "<h4>Kieth's Variables</h4> <p>";    # insert html header + p tag 
       
# output the type of the variable $intvar      
print 'the type of the variable $intvar is: '.gettype($intvar); 

       echo "<br>";    
 
# output the type of the variable $floatvar      
print 'the type of the variable $floatvar is: '.gettype($floatvar); 

       echo "<br>";    

       # output the type of the variable $string      
print 'the type of the variable $string is: '.gettype($string); 

       echo "<br>";    
         
# output the type of the variable $thisvar      
print 'the type of the variable $thisvar is: '.gettype($thisvar); 

       echo "<br>";    

# output the type of the variable $that      
print 'the type of the variable $that is: '.gettype($that); 

       echo "<br>";    
        
# output the type of the variable $other      
print 'the type of the variable $other is: '.gettype($other); 

       echo "<br>";    
        
# output the type of the variable $what      
print 'the type of the variable $what is: '.gettype($what); 

       echo "</p>";    # closing Kieth's Variables Paragraph

echo "<h4>Test print string</h4> <p>";    # insert html header + p tag 
/*      these lines were when Whoever inside the Greeter string constant was set to $user and nothing printed. the webpage displayed "Notice: Undefined variable: user in /students/mchen75/public_html/cs130a/lab3/index.php on line 38 Notice: A non well formed numeric value encountered in /students/mchen75/public_html/cs130a/lab3/index.php on line 68 Notice: A non well formed numeric value encountered in /students/mchen75/public_html/cs130a/lab3/index.php on line 69" but was not visible under view-source: 

echo Greeter;       #echo const, $user inside doesn't show up     
echo "<br>";        
         
print Greeter;      #print const, $user inside doesn't print
echo "<br>";   
*/
       
echo Greeter;       #echo const, string prints normally   
echo "<br>";        
         
print Greeter;      #print const, string prints normally  
echo "<br>";   
       
echo "Greeter";     #echo const in "", returns const name
echo "<br>";
         
print "Greeter";    #print const in "", returns const name
echo "<br>";   
              
echo 'Greeter';     #echo const in '', returns const name  
echo "<br>";
         
print "Greeter";    #print const in '', returns const name
echo "<br>";         
       
echo "$Greeter";    #echo string var in "", returns Greeting with expanded $user
echo "<br>";
         
print "$Greeter";    #print string var in "", returns Greeting with expanded $user
echo "<br>";       
       
echo '$Greeter';    #echo string var in '', returns string var name
echo "<br>";      

print '$Greeter';    #print string var in '', returns string var name
echo "<br>";   
       
echo "</p>";    # closing Test print string Paragraph
    
?>     


    <p class="hide">
    this is a blank paragraph to do nothing but take up space and ensure the formatting works
    </p>
    <div class="stretch"></div>
</body>
</html>