Marc Fraser | A Blog about all things A blog about all things personal, web related.

10Oct/090

Outputting HTML using PHP [+ Semicolons]

(from Full Article)

Semicolons

Semicolons are used extensively in PHP. The semicolon generally (there are exceptions) signifies the end of a PHP statement and should not be forgotten, otherwise unsightly errors will occur. An example will be shown in the Outputting HTML code using PHP section.

Outputting HTML code using PHP

Outputting HTML code using PHP is extremely easy. It can be done using the PHP Print command or indeed PHP Echo. The difference between the two commands can be read on the PHP FAQts site.

Below is how to output “This is my first output PHP string” in HTML paragraph and bold tags. This example will also show how the semicolon is used (read prior section, Semicolons).

<html>

<head>

<title>My first PHP outputs</title>

</head>

<body>

<?php

print “<p><strong>This is my first output PHP string</strong></p>”;

// For consistency I will show the use of the echo command

echo “<p><strong>This is my first output PHP string</strong></p>”;

?>

</body>

</html>

If you run the above code, you will see that you get the output:

First PHP output
First PHP output.

The first line is of the print command and the second line is the output of the echo command. Please note that there is no difference between the two. Please also note the usage of quotation marks – these are used to tell the PHP code that we wish not to execute the contents contained within.

10Oct/090

PHP Comments

(from Full Article)

We place comments in PHP code to make the code more maintainable and readable. These comments will not be viewable to the public, only to the person editing the PHP file. To comment in PHP we should prefix ‘//’ to our comment, for example:

<?php

//This is our comment

?>

We can also place comments over multiple lines by using ‘/*’ to begin and ‘*/’ to end our comment – as shown below.

<?php

/* This is a

comment set

over multiple

lines */

?>

Comments will be a lot more useful when more advance techniques in PHP are used.

A basic page in PHP is shown below, using our start, and end tags as well as comments. Please note that nothing will show, as comments are being used.

<html>

<head>

<title>First PHP Comments</title>

</head>

<body>

<?php

// This is a comment and will not be shown to the public

/* This is a multi-line comment and will not be shown

to the public */

?>

</body>

</html>
10Oct/090

Create a PHP File and Begin

(from Full Article)

The first thing that all developers need to do is create a blank PHP page. This can be done by simply opening up Notepad and creating a new file – but instead of saving it with the ‘.txt’ affix, change it to ‘.php’. Alternatively, users that have dedicated editors such as Dreamweaver, etc. can create a blank PHP page by selecting File menu and create new PHP page.

Now that we have our blank PHP page we can begin.

Tell the server we wish to begin execution

We have to tell the server that we wish to execute PHP code, otherwise when the user requests the page, nothing dynamic will happen and instead it will just show our PHP code as plain text.

We use ‘<?php’ to start our PHP code and then  ‘?>’ to end. The ‘<?php’ tells the server that the code we wish to start executing is PHP, and ‘?>’ to end executing our PHP code. Outside of these brackets is where our HTML code should go which should not be dynamically updated, such as our Headers, Footers, etc.

You can use the shorthand PHP beginnings (‘<?’) and endings (‘?>’) but this is not recommended as servers do not always support these.

10Oct/091

Benefits of PHP

(from Full Article)

PHP will reduce time to create and maintain medium to large websites – due to the pages being dynamic, only a small number of PHP pages will need to be created/edited which will allow the use of a Database (commonly MySQL), containing the websites’ content. The contents of the database are extracted by PHP and a page is created ‘on-the-fly’.

A few more of PHP’s benefits are shown below:

  • Allow the website to customize each users experience, based on information gathered from them.
  • Create websites that allow users to purchase items off a website (known as ecommerce).
  • PHP users can download and use many free Open Source PHP tools on their website.
  • As PHP is executed on the server this means that the PHP is not dependant on the users’ computer settings. For example, a user requesting a page in Firefox will get the same PHP Output as that of a user viewing in Internet Explorer, but please bear in mind that the way the HTML/CSS output is formatted may differ between the two. You will most likely have met this if you have used HTML/CSS to an intermediate level.
  • All PHP’s commands are described and examples given in the PHP Online Manual.
6Oct/090

An update (and apology!)

Over the last week, I've not had the time to implement my own Wordpress theme and in the meantime I've chosen to use one from the Wordpress Website - the default ones aren't very good.

I've added a PHP tutorial which I wrote for TWS, it is on the very basics of PHP.  Have a read. Feedback is, of course, always welcome.

This leads me onto another point: if you wish me to cover any specific topics, please ask me.  I'm going to add a contact form now.

Filed under: Site News No Comments

Bad Behavior has blocked 88 access attempts in the last 7 days.