logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
European Travel
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel


dailyclick
All times in EST

Clairvoyance: 08:00 PM

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

How To Use HTML and PHP On The Same Webpage

Guest Author - Diane Cipollo

One of the features that make PHP such a popular language is that you can mix your HTML and PHP code together on the same page. There are just two simple rules you need to remember. You will need to change the extension on the end of the name of the webpage. Secondly, wrap your PHP code inside the opening and closing PHP tags.

  • Webpage Extension

    You will need to change the extension on the name of your webpage from .html to a PHP extension. Your web host can tell you which PHP extension to use for the server you are on. First check the online documentation. If the answer is not there you can email your web host. Usually the extension will be either .php or .php3.

    Example: mywebpage.html ------> mywebpage.php3


  • Opening and Closing PHP Tags

    You will enclose all of your PHP code between opening (<?php) and closing (?>) tags. This is how the server can tell the HTML and the PHP code apart.

OK, now we are ready to create a webpage that contains both PHP and HTML. First you will want to code the top part of the webpage using HTML. Open you text editor and add this code.

<html>
<head>
<title>Sample 2</title>
</head>
<body>

Next we will add some PHP code that will print either "Good Morning" or "Good Evening" depending on the time of day that the webpage is viewed. If the hour of the day is before noon, then "Good Morning" will be printed. If the time is noon or later, then "Good Evening" will be printed. I know we haven't discussed the PHP code in detail, but take a look at it anyway. I bet you can figure out how it works. Then add the PHP code to the webpage.

<?php
$current_time = date(G);
if ($current_time < "12") {echo "Good Morning<br>";}
else {echo "Good Evening<br>";}
?>

Finally add the code below to finish the rest of the message and the end of the webpage using HTML. Click here to view the entire code.

Welcome to my website.

</body>
</html>

Now save your webpage. Call it "sample2.php3" (or sample2.php) and put the file in the following location.

C:\sokkit\site\sample2.php3

Finally we will test the webpage. Open the Sokkit Control Panel and RIGHT click on the View Site button. Choose "Open in New Window" from the pop-up list. This will cause the sokkitdefault.html webpage to be displayed in the new window. You should see a message saying "This site is powered by Sokkit 3.4". Now go to the url address line in the web browser. It should say http://localhost/. To test your webpage, add sample2.php3 at the end of this and click Enter. You will see a white page with the following.

Good Morning (Good Evening)
Welcome to my website.




This site needs an editor - click to learn more!

Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Twitter Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Facebook Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to MySpace Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Del.icio.us Digg How+To+Use+HTML+and+PHP+On+The+Same+Webpage Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Yahoo My Web Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Google Bookmarks Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Stumbleupon Add How+To+Use+HTML+and+PHP+On+The+Same+Webpage to Reddit




RSS | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor