Welcome to Virtual Tutorial World Guest!



Everything PHP

 
Post new topic   Reply to topic    VTW Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Please Register and Login to this forum to stop seeing this advertsing.





Tokens:


Posted:     Post subject:

Back to top
computergeek67
Administrator
Administrator


Joined: 31 Jul 2007
Posts: 144


Tokens: 147
Location: US

PostPosted: Sun Oct 21, 2007 5:02 pm    Post subject: Everything PHP Reply with quote

Overview

PHP stands for PHP: Hypertext Processer. PHP is used for creating interactive web applications. And, with more knowledge, you can create massive, feature rich applications. Even this forum system that you are using now was created with PHP. So, lets get started.

Embedding PHP in HTML

One of the nice things in PHP is that you can embed commands in regular HTML. These embedded commands are written with special start and end tags. Here is an example of what these tags look like:
Code:
<?php
//php code
?>

To actually see PHP in action, create this simple script, which demonstrates how PHP and HTML can be combined:
Code:
<html>
<head></head>
<body>
<h2>Q: What is 2+2?</h2>

<?php
//print output
echo '<h2><i>A: 4</i></h2>';
?>
</body>
</html>

Save the script in your web server root as question.php, and browse to it. The page should look somethign like this:
Quote:
Q: What is 2+2?

A: 4


Writing Comments

For greater readability and to help poeple understand the code, you should add comments to your PHP code. Examples are listed below:
Code:
<?php
//this is a single line comment

/* and this is a
multiline
comment */
?>


Storing Values in Variables

Variables are the building blocks of any language. Variables can consist of both numeric and non-numeric data.

PHP variable always start out with a dollar sign ($), which is followed by the variable name. For example, $tutorial, $hi, and $you are all valid PHP variable names.

Note that PHP variables are case-sensitive meaning that $hello is different from $Hello or $HELLO.

Assigning Variable Values

To assign a variable, the use of the equal sign (=) is necessary. This operator assigns a value to a variable. To use a variable in your script, call the variable by name, and PHP will substitute its value. Here is an example:
Code:
<?php
$today = "October 21, 2007";
echo "today is $today";
?>


Saving Forum Input Variables

Forms have always been the easiest and quickest ways of adding interactivity to your site. You can use forms for emailing, comments, or asking costomers if they like your products. PHP can simplify the task of forms by using variables. Take this script for example:
Code:

<html>
<head></head>
<body>

<form action="message.php" method="post">
Enter Your Message: <input type="text" name="message" size="30">
<input type="submit" value="Send">
</form>

</body>
</html>

The method attribute of the <form> tag specifies the manner of how the data will be submitted, while the action attribute specifies the name of the PHP file (in this case, message.php), that will process the information. Here is what message.php would look like:
Code:
<?php
//retrieve from data in a variable
$input = $_POST['msg'];
//print it
echo "You said: <i>$input</i>";
?>

To see how this works, enter some data into the form ("Hello World!") and submit it. The form processer should read it and display it back to you ("you said: Hello World!").



_________________



Come to me if you have any questions
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    VTW Forum Index -> PHP All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Virtual Tutorial World ©2007-2008 computergeek67

Affiliates