Skip to main content
  1. Tech
  2. Gadgets & Tech
  3. Tech Gear

Using functions in a PHP program (part 1)

See also

As your programming code grows, it is much easier to use functions. Functions are pieces of code that are more manageable and you can reuse the same programming code wherever it is necessary to perform a specific task. A function is a group of PHP statements within a PHP program that work independently. PHP has a number of built-in functions; you can also create your own functions.

The PHP programming code listed below demonstrates displaying a company logo.

NOTE: The jpeg images are stored in the "C:\WAMPSERVER\www\images" folder. As demonstrated in the previous programs, we used notepad a plain text editor. The PHP programs are stored on our web server, "C:\Wampserver\www." Please note the stored web server location.

Now let us create the PHP program, please follow the steps outlined below:

  1. Select and click "Start."
  2. Select and click "All Programs."
  3. Select and click "Accessories."
  4. Select and click "Notepad."
  5. Type the PHP code exactly as shown below.
  6. Once you have type the entire program, Select "File," "Save As," and then go to the webroot of your server. For example, C:\Wampserver\www. Type Filename, "logo.php," and then Select "Save."

<html>

<head>

<title>LOGO</title>

</head>

<body>

<h1>LOGO</h1>

<h3>Demonstrates LOGO<h3>

<?php

print "<p><img src = 'images/JONESLOGO.jpg' width='700' height='125'/><p>";

print "<p style='font-size: large'>The Finest Florist </p>";

print "<p style='font-style: italic'>beautiful creative designs</p>";

?>

<br>

</body>

</html>

As shown it takes three lines of code to display a company logo.

Use your browser to view the logo.php program. The steps are outlined below:

  1. Select and click "Start. "
  2. Select and click "All Programs."
  3. Select and click "Internet Explorer."
  4. Locate the Web Address Field, near the top-left of the Internet Explorer window and type in the Web address of the logo.php program, "http://localhost/logo.php," then enter.

In our next article, Using functions in a PHP program (part 2), we will demonstrate how to use the function block.

Advertisement

Don't Miss

  • Massive
    Ubisoft Massive exclusive: 'The Division', PS4 & Xbox One, Activision to Ubisoft & more
    Camera
    Games Exclusive
  • iPhone
    Get your wallet ready: The next iPhone could cost $100 more than your last one
    Video
    Tech Buzz
  • Civ
    Need to catch up on 'Sid Meier's Civilization'? Here is everything you need to know
    Camera
    Games Feature
  • Google Glass
    See how Google Glass is letting sick kids go to the zoo without leaving the hospital
    Tech News
  • Upcoming
    These are 2014's biggest PS4, Xbox One and Wii U games
    Camera
    Games Feature
  • Google
    Google has filed for a patent to develop contact lenses capable of taking photos
    Video
    Headlines

User login

Log in
Sign in with your email and password. Or reset your password.
Write for us
Interested in becoming an Examiner and sharing your experience and passion? We're always looking for quality writers. Find out more about Examiner.com and apply today!