Create your web page with NetBeans –Part 3

In this part we will look into PHP basics

PHP is a widely used open source,general-purpose scripting language. It was originally designed for use in Web site development.  PHP proved so useful and popular,it rapidly grew to become the full-featured language that it is today,acquiring the name PHP Hypertext Preprocessor along the way to represent its expanded abilities — processing Web pages before they’re displayed.

PHP is a server-side scripting language,which means that the scripts are executed on the server. This is different than JavaScript,another popular language for dynamic Web sites. JavaScript is executed by the browser,on the user’s computer. Thus,JavaScript is a client side language.

NetBeans 6.7 Beta have good support for PHP,so there is no need to learn another editor.

PHP is particularly strong in its ability to interact with databases. PHP supports pretty much every database you’ve ever heard of and some you haven’t. PHP handles connecting to the database and communicating with it,so you don’t need to know the technical details for connecting to a database or for exchanging messages with it. You tell PHP the name of the database and where it is,and PHP handles the details. It connects to the database,passes your instructions to the database,and returns the database response to you.

This are all databases supported by PHP

MySQL,Oracle,PostgreSQL,Sybase,  dBASE,Informix,Ingres,Microsoft SQL Server,mSQL + others.

Code on server side vs. code in browser

In part 2 we typed this code in the editor

<?php echo "Hey hey,My first PHP project is working!";?>

in the browser source it shows this

  <body>Hey hey,My first PHP project is working!</body>

As you can see,the PHP code on the server has been sent to the browser as HTML code.

If you want to see all information about the PHP version running on your server insert this code after the other line

<?phpecho "Hey hey,My first PHP project is working!";phpinfo();?>

Run this program now and you should get a long page with all types of information about the PHP on the server. This code should of course not be on a public page,since it gives away too much information.

Variables

A variable starts with a dollar sign ($) and it can be any length,it can include letters,numbers,and underscores only. A variable is case sensitive,so small and capital letters are not the same. Variable names must begin with a letter or an underscore. They cannot begin with a number.

Creating descriptive variable names by connecting words with an underscore or by using uppercase letters to denote the beginning of new words.

$myBestFriend$my_best_friend

Naming your variables by using one of these two common styles makes it easier for other programmers to read your scripts. It’s also common to start the name with a lowercase letter. The most important factor in naming variables,however,is to be consistent. Pick a style and use it throughout the entire script.

Now lets go to NetBeans again and put our message in a variable

<?php$myMessage = "Hey hey,My first PHP project is working!";echo $myMessage;?>

Run it now and see whats happens,it should be working like before.

If you want to put a variable inside a sentence,do it like this

<?php$myMessage = "My first PHP project";echo "Hey hey,{$myMessage} is working!";?>

It’s a good idea to use curly braces{} around the variable,its not always needed but if you want your variable to be a part of a word then you need it.

Inserting date

        <?php        echo date ("l j F Y");        ?>

This is just an example,we will cover all the details in a later post.

Lets put some HTML tags on the code

        <?php        $myMessage = "My first PHP project";        echo "<h3>{$myMessage}</h3>";        echo "<p><em>Hey hey,{$myMessage} is working!</em></p>";        echo date ("l j F Y");        ?>

<h3></h3>is header 3 tag,<p></p>is the paragraph tag and <em></em>is the emphasis tag. When we are using tags,then the script is prepared for css (cascading style sheet). It’s then easy to change the style of the page with an external (or integrated) css file. We will collect the HTML tags in a separate post later.

Now we will put some css style inside the code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">        <title></title>        <style type="text/css">        h3{color:#ff0000}        p{color:rgb(0,0,255)}  p{font-family:courier}        </style>    </head>    <body>        <?php        $myMessage = "My first PHP project";        echo "<h3>{$myMessage}</h3>";        echo "<p><em>Hey hey,{$myMessage} is working!</em></p>";        echo date ("l j F Y");        ?>    </body></html>

In the <head></head>section we inserted a <style></style>tag to describe the css settings for h3 and p.
h3{color:#ff0000} sets the header3 color to red,and p{color:rgb(0,0,255)} sets the paragraph color to blue. This is 2 ways to set the color.

p{font-family:courier} will set the paragraph font to the courier family font.

That is it for this part,we will continue this introduction series in Part 4.

1 comment to Create your web page with NetBeans –Part 3

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>