(watch this video in a new tab or window)
PHP is a popular general-purpose scripting language that is especially suited to web development. It is very powerful and is widely used. Up to now, all of our content has been static, which means you typed something, saved it, and viewed it on the web. With PHP, you will begin to use dynamically created content. You can type something like:
<?php
echo date('Ymd');
?>
on your web page and when you view it you'll see today's date in year month day format.
(watch this video in a new tab or window)
PHP needs to be installed on your website. At Miami, it's already been installed. To create a new PHP document, you can just copy an existing document and change the extension to php. You can begin and end PHP multiple times in the document if you want to, or you can wrap the whole thing in PHP. To begin PHP type '<?php' and to end PHP type '?>'. When you're in PHP, you can still create HTML by using 'echo'. The following will say 'Hello World':
<?php
echo 'Hello World';
?>
Now let's put that in bold:
<?php
echo '<b>Hello World</b>';
?>
Now let's make it a header:
<?php
echo '<h1>Hello World</h1>';
?>
Now let's make a list:
<?php
echo '<ul><li>John<li>Bob<li>Bill<li>Rick<li>Steve</ul>';
?>
Here's the same list a few different ways, all with different code formatting but with the same HTML formatting:
<?php
echo '<ul>
<li>John
<li>Bob
<li>Bill
<li>Rick
<li>Steve
</ul>
';
?>
or
<?php
echo '<ul>
<li>John</li>
<li>Bob</li>
<li>Bill</li>
<li>Rick</li>
<li>Steve</li>
</ul>
';
?>
or
<?php
echo '<ul>';
echo ' <li>John</li>';
echo ' <li>Bob</li>';
echo ' <li>Bill</li>';
echo ' <li>Rick</li>';
echo ' <li>Steve</li>';
echo '</ul>';
?>
or
<?php
echo '<ul>';
echo ' <li>John</li>';
echo ' <li>Bob</li>';
echo ' <li>Bill</li>';
echo ' <li>Rick</li>';
echo ' <li>Steve</li>';
echo '</ul>';
?>
Here's a loop to show you some of the power of PHP.
$ThisManyRounds=3;
for($round=1;$round<=$ThisManyRounds;$round++){
if($round==1){$Topic='American Literature';}
if($round==2){$Topic='Mathematics';}
if($round==3){$Topic='World History';}
echo $round.') '.$Topic.'<br>';
}
See if you can change the loop to show the dates of the last 180 days in the following format:
Day of the Week, Month-Day-Year
Good luck.
Here's code to get you started:
$ShowThisManyDays=30;
for($day=-10;$day<=$ShowThisManyDays;$day++){
$TheDay=date('F m-d-Y, l',
mktime(0,
0,
0,
date('m'),
(date('d')+$day),
date('Y')
)
);
echo $TheDay.'<br>';
}
513.529.6700 | email | Email Form
105 Harris Hall, Oxford, OH 45056
My office (105 Harris Hall) is on the right side of the building as you walk in to Harris dining hall. I'm on the right as soon as you walk in the building.
Find my office via Google maps
Office Hours prior to 03-10-2017: 10:45am-11:45am on Friday's or by appointment
Based on student feedback, beginning 03-10-2017, "Office Hours" have been replaced with class time from 11am-11:45am on Friday's in 205 Laws Hall