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

Using functions in a PHP program (part 2)

See also

As we continue with the series of Using functions in a PHP program, the next program will demonstrate the function block. As shown in the Using functions in a PHP program (part 1) article, in order for us to display a company logo throughout a document, three lines of code are required, these lines of code are typed each time the company logo is shown. To remedy the repetition of typing the three lines of code, the function block is used. The format is shown below:

function functionname()


block of statements;



The PHP programming code listed below demonstrates displaying a company logo two times in the same script.

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, "logotwice.php," and then Select "Save."







<h3>Demonstrates LOGO<h3>


function logo()


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>";



print "<p><h1>Here is the first Jones Florist Logo</h1><p>";




print "<p><h1>Here is the second Jones Florist Logo</h1><p>";






In the logotwice.php program, the function block is identified as "function logo()", each time you want the company code to be displayed all you need to do is call the function by using "logo()."

Once displayed on the internet, the function block eliminates the need to type the three lines of code each time the company logo is needed to be displayed. This is definitely a more sufficient method to use.

Use your browser to view the logotwice.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 logotwice.php program, "http://localhost/logotwice.php," then enter.

Don't Miss

  • Massive
    Ubisoft Massive exclusive: 'The Division', PS4 & Xbox One, Activision to Ubisoft & more
    Games Exclusive
  • iPhone
    Get your wallet ready: The next iPhone could cost $100 more than your last one
    Tech Buzz
  • Civ
    Need to catch up on 'Sid Meier's Civilization'? Here is everything you need to know
    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
    Games Feature
  • Google
    Google has filed for a patent to develop contact lenses capable of taking photos

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 and apply today!