Skip to content

Instantly share code, notes, and snippets.

@safranck
Last active August 29, 2015 14:15
Show Gist options
  • Save safranck/773ba1b3c92aae864d33 to your computer and use it in GitHub Desktop.
Save safranck/773ba1b3c92aae864d33 to your computer and use it in GitHub Desktop.
Introduction to PHP and MySQL: PHP 101
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//create a function called cupid that outputs a string
function cupid() {
// the cupid function outputs a red XoXoX when called
echo "<p style='color: red;'><b>XoXoX</b></p>";
}
//create a function called myDate thta output today's date
function myDate() {
//Define the variables
$year = date('Y'); // get current year
$month = date('M'); // get month
$date = date('j'); // get day of the month
$day = date('l'); // get day of the week
//Build the date string
$today = $day;
$today .= ', ';
$today .= $month;
$today .= ' ';
$today .= $date;
$today .= ', ';
$today .= $year;
//Show us the results
echo $today;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Welcome!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="robots" content="noindex" />
</head>
<body>
<div id="page">
<div id="header" class="header">
<h1>Welcome to Miss Suzette&#39;s Class</h1>
</div>
<div id="content">
<?php
// Calling the cupid function, which will output a string
cupid();
?>
<h3>Today is <?php echo myDate(); ?>.</h3>
<?php
// Create and define the $eggs variable
$eggs = 1;
$eggs = TRUE;
$eggs = array('fried', 'poached', 'boiled');
// this code will put the results of var_dump in an HTML comments
echo '<!--';
var_dump($eggs);
echo '-->';
// re-defining the $eggs variable
$eggs = NULL;
$eggs = 'someone\'s';
// this code will put the results of var_dump in an HTML comments
echo '<!--';
var_dump($eggs);
echo '-->';
if ( is_null( $eggs ) ) {
// code to be executed if true
echo '<p>Sorry! No eggs for you!</p>';
} else {
// code to be executed if false
echo "<p>You deserve ";
echo $eggs;
echo " heart for Valentine's Day. </p>";
}
$year = date('Y'); // get current year
$month = date('M'); // get month
$date = date('j'); // get day of the month
$day = date('l'); // get day of the week
?>
<h1>
<?php echo $year; ?>
</h1>
<ul>
<li>
<?php echo $day; ?>, <?php echo $month; ?>. <?php echo $date; ?>
</li>
</ul>
</div>
<div id="footer">
<p>Powered by <a href="http://girldevelopit.com">Girl Develop It</a></p>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment