Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Basic Php Tutorial
ghostrider
post Jul 3 2006, 06:27 PM
Post #1


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



Hypertext Preprocessor, or PHP for short, is a dynamic language, meaning that unlike HTML, PHP can change itself without you having to update the page using FTP or the CPanel. PHP has endless possibilites, you can use MySQL (a database program) with it, create polls, counters, work with images, process forms and CGI, and even send email. In order for you to start PHP coding, you need to tell the server that is processing your webpage that this is PHP. You can do that 3 seperate ways.

CODE
<script LANGUAGE="PHP">

CODE
<?PHP

CODE
<?


After you have done that, you can start writing in PHP. The first function that you will learn is echo().
Echo() will output a string of text that you specify. Here is an example:
CODE
<?PHP
echo("Hello World!");
PHP?>


Each line of code in PHP ends with a semicolon (wink.gif. This is very important, if you don't do this, your program will crash with a fatal error.

Another way you can do the same thing is like this:
CODE
<?PHP
$thisisavariable = "Hello World!";
echo("$thisisavariable");
PHP?>


$thisisavariable is a variable. All variables have a dollar sign ($) before them. Variables can also contain numbers, as shown below.
CODE
<?PHP
$var = 123;
PHP?>


Comments can be shown in PHP also, they are placed after semicolons and have "//" before them.
CODE
<?PHP
$var = 123; // Put the number 123 in the variable $var.
PHP?>


Below is an example of what you can do with PHP. It will be commented so you can follow along.
This is how it works:
Check to see if the user has specified their name. If not, display a form so they can enter there name. If they have entered there name print "Hello, (user's name here)!".
CODE
<?PHP //Tell the server that to process the PHP.
if ($_GET['name'] <> "")  //If statements do not need semicolons.
{ //This just means this is where the code for the if statement starts.
// This code is run if they have specified their name.  The <> means not equal.
$user_name = $_GET['name']; //Put the user's name is $user_name.
echo("Hello, $user_name");
}
else // This means that the user did not specify a name yet.
{
echo("Please type your name and press Submit:");
echo("<FORM ACTION='3.php' METHOD='GET'>");
//Notice I am using single quotes inside of echo.  If you were to use double quotes you would crash your program.
echo("<INPUT TYPE='text' NAME='name' LENGTH='30'>");
echo("<INPUT TYPE='Submit' VALUE='Submit'>");
}
PHP?>


I really hoped this helps some people start to learn PHP. Any questions, comments or constructive critiscism (this is my first tutorial) can be posted and I will answer them. I'll post the links to the 3 examples (Hello World, Hello World (with a variable), and the example once I get enough credits to become active again smile.gif.

Go to the top of the page
 
+Quote Post
NeOniX
post Jul 7 2006, 07:10 AM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 22
Joined: 17-June 06
From: Nebuchadnezzar, dock 6, Zion
Member No.: 25,271



Well, i want to colaborate with this post so i expose lil thingz related to simple maths to be used in PHP:

Operators are the common on most of programming languages, * for multiplying (3x2 = 3*2), + for sum (3+2 = 5), - for resting (3-2 = 1), / for division (3/2=1.5), and ^ for exponentials (3^2 = 9).

So if you want to sum some stored variables (of a DB, or whatever you want/need biggrin.gif) you could do the next:
CODE

<?
$var1= '3';  // that could come from a form if you replace the '3' string with a $_GET[''] or $_POST['']
$var2= '2';  // ... the same :P

settype($var1, 'integer');  // That makes a string into an integer, i.e. '5a' it will be converted into the number 5.
settype($var2, 'integer');  // The same for the $var2

/* You could ask why didnt i wrote "$var1=3;" instead of "$var1='3'", i did that cuz in the forms most of times is sent as a string, and the ppl could write 5a, 3v, c, so the settype makes the string to an integer (the integers dont have ' for delimitating) */

$sum = $var1+$var2;
echo $var1.' and '.$var2.' equals to '.$sum; // You'll have to get something like "3 and 2 equals to 5"
?>


It was a micro help, but from that, you could figure out to use -, *, / and ^ hehe.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Archive.org The Public Domain And Basic Copyright(1)
  2. Simple C File Handling In Action(4)
  3. [tutorial] Visual Basic 6 Minimize To Tray(7)
  4. Aob Blood Grouping(4)
  5. [tutorial] Visual Basic 6(4)
  6. Basic Ways To Speed Up Your Web Site(25)
  7. How To Make A Web Browser(49)
  8. Visual Basic 6.0 Help Needed(15)
  9. Basic Of Website Creation(9)
  10. Making A Simple Signature With Adobe Photoshop(3)
  11. Simple Login In Visual Basic 6(6)
  12. Ftp In Visual Basic 6.0(1)
  13. Help! Php Or Just Html?(13)
  14. Ti Basic: Pick A Number(1)
  15. Ti-basic --- Slot Machine(9)
  1. Need Help With My Python Programs(11)
  2. Buliding A Basic Community Site(2)
  3. A Twist On Basic Authentification(1)
  4. Some Basic But Important Info About Cancer(3)
  5. Learn Russian(7)
  6. Java Basic Program Guidance(6)
  7. Mysql In Visual Basic(5)
  8. Creating A Timer Program(8)
  9. Photoshop Tut: Basic Text (video)(0)
  10. Photoshop Tut: Basic Sig (video)(0)
  11. My First C++ Program(6)
  12. Two Really Good 2d Mmo Engines(1)
  13. [vb.net 2k5] Countdown (help)(2)
  14. Basic Percussion Composition(0)
  15. Basic C++ : Tutorial 2(0)


 



- Lo-Fi Version Time is now: 7th October 2008 - 10:30 PM