Page 1 of 1

Php tutorial - The Basics - Part 1 For new comers to php Rate Topic: -----

#1 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Posted 05 June 2010 - 07:11 AM

*
POPULAR

Welcome,

Everyday the world wide web(WWW) keeps getting more advanced, people thinking of new ways to produce top quality products for Gamers/Programers Clients and More.

In this tutorial, i will/try to explain the basics behind Php.
This tutorial will cover:

  • Introducing Php
  • What you will Need
  • Getting Started
  • Your first script
  • Variables
  • Operators


Introducing Php

Php is a server side scripting language, that Coders use to execute .php scripts to create websites.
Php can create a wide veriety of things like, Textbased/2D game engines, social Networks like Facebook,Twitter and Myspace, Filesharing websites like rapidshare, Forums like Dreamincode or bethesda forums.
Some people can use php to create there own encryption algorithms like the md5 hash.
You DO Need a server to execute the php scripts though.

Php Stands for Php:Hypertext[/b] P[/b]reProcessor.




What you will Need

To execute your php scripts, you will need a server to execute them on, i suggest (if you dont have a server alreadey) you use wamp server.

Wamp server Is a free,easy to use server, i use it because its smaller than downloading all the Php/Apache/Mysql
programs, and it come configured, so no fidleing around :)

You might also want to use an WYSIWYG editor - i use zend studio, but you can use witch ever one you wish.




Getting Started
If you have completed the What you will Need Step, then run the installer(s), and configure as you please.


Open your WYSIWYG editor and click "Save As" and save it as - "myfirstscript.php" Remember the ".php" bit, because, you have to have it or the editor will not save it as a php script.

Ok, We're done here, lets move on to the exciting stuff shall we.




My First Script
<?php
echo "Hello World!";
?>


What is that you say, well it's one of the simplest scripts written in php.
Lets go through the above script.
  • <?php - This tells the compiler that the script is belongs to the Php languge.
  • echo "Hello World!"; - This will display Hello world! onto your screen.
  • ?> - This tells the server to end the php script

Was that simple, i hope it was easy to understand.

So, You have just learnt ho to make your own php script.
Easy, Bah, nothing to it once you get the hang of it =]




Variables
Do you remeber algebra from school, and thinking "Were in life would i use that".
Well in php is were. Some websites revolve around equations and algorithms.

well php uses things called variables, witch scripts store things in.
variables are defined by the dollar sign "$".
Say for example,
<?php
$x = 1;
?>


The code above makes a new variable called "i" witch we had just stored the number 1 to.
You can store mostley everything you want in variabls, from numbers,strings(abc),arrays,sql queries and functions.
So lets try this one aye
<?php
$string = "My name is";
$name   = "Aaron";
$final  = $string . " " . $name;
echo $final;
?>


The above code will output "My name is Aaron".
This uses a function known as concatenation
This will join the $string variable with the $name variable.

what You've learnt
I hope you have been listening =] because you will eaither come across variables sooner or later.




Operators
Operators are signs that php use to determine things.
For example, = means equal to

  • = - Equal To
  • ! - Is Not
  • < - Is lower than
  • > - Is higher than
  • || - Or
  • && - and
  • != - Is Not equal to
  • <= is lowerthan or equal to
  • >= - Is


What you have learned
You should have learnt, most of the php operators, that evolve around php




In the next tutorial you will learn:
  • Functions
  • Switch functons
  • If - Statement
  • If - Else - statement
  • If - elseif - else
  • While Loops


thanks for listerning, i hope you have learnt some new things that you might not or did not know.

Thanks Aaron1178

Is This A Good Question/Topic? 6
  • +

Replies To: Php tutorial - The Basics - Part 1

#2 dasker  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 10-November 10

Posted 16 March 2011 - 03:50 PM

I am a beginner and I just loaded the the Php/Apache/Mysql.
I am not sure how to organize my files / path to be able to run the programs I write. I tried from the command line to run the simple Hello World prpgram to test ou the path but I get the following:

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\>dir
Volume in drive C is Local Disk
Volume Serial Number is 5CBE-C468

Directory of C:\

03/11/2011 02:44 PM <DIR> Apache2
01/21/2010 11:19 AM <DIR> AZTAZ
01/12/2010 04:48 PM <DIR> BegPerl
12/11/2008 03:57 PM <DIR> borland
08/18/2010 05:27 PM <DIR> Dev-Cpp
07/09/2009 08:38 AM <DIR> Documents and Settings
08/28/2007 01:27 PM <DIR> Drivers
03/16/2011 09:24 AM <DIR> Exchange
02/16/2011 04:18 PM 0 final.gds.gz
01/09/2011 12:58 PM <DIR> glassfishv3
02/06/2009 12:13 PM <DIR> ICON
02/03/2011 12:16 PM <DIR> Java
01/26/2011 08:19 PM <DIR> jdk1.6.0_23
03/11/2011 02:44 PM <DIR> MySQL
09/09/2010 12:40 PM <DIR> Perl
03/11/2011 02:44 PM <DIR> PHP
02/17/2011 04:06 PM <DIR> Program Files
07/30/2010 01:42 PM <DIR> Tellabs
09/18/2008 04:23 PM <DIR> Temp
01/27/2011 11:01 AM <DIR> TIJ4
02/26/2008 08:37 PM <DIR> Umcfiles
03/16/2011 09:02 AM <DIR> WINDOWS
1 File(s) 0 bytes
21 Dir(s) 70,313,746,432 bytes free

C:\>cd php

C:\PHP> hello.php
'hello.php' is not recognized as an internal or external command,
operable program or batch file.

C:\PHP>

could someone let me know. My file Hello.php is in a folder on my desktop.
Should it be somewhere else?
What is Apache doing?
What is MySQL doing?

Thanks
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Posted 17 March 2011 - 03:35 AM

Quote

I am a beginner and I just loaded the the Php/Apache/Mysql.

How did you install it? Did you use WAMP or XAMPP?

Quote

C:\PHP> hello.php
'hello.php' is not recognized as an internal or external command,
operable program or batch file.

PHP is not an executable file format. You need to find the PHP CLI exe and use it like this:
<path_to_php_exe> -f hello.php

Was This Post Helpful? 0
  • +
  • -

#4 dasker  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 10-November 10

Posted 17 March 2011 - 09:55 AM

I am not sure if it was WAMP or XAMMP
if I look in the folder that I saved it to on my desktop the file there is: ApachePHPMySQL-1.1.exe
What is Apache doing?
What role does MySQL?
I copied the simple Hello.php and wanted to run it from my windows cmd line and I get Hello.php is not a recognized command?

Can ya point to some good documentation that will walk me through setup and confirm it is loaded correctly.
Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Posted 17 March 2011 - 10:27 AM

Uninstall what you installed and go download this instead and install it.
Was This Post Helpful? 0
  • +
  • -

#6 dasker  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 10-November 10

Posted 17 March 2011 - 12:04 PM

Ok I installed it and I have my WAMPSERVER online.
Where do I go to check if all is well and if I grab my Hello.php program where do I run it to see if it works?

Thanks BTW.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Posted 17 March 2011 - 05:23 PM

https://encrypted.go...erver+tutorials
Was This Post Helpful? 0
  • +
  • -

#8 dasker  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 10-November 10

Posted 18 March 2011 - 10:22 AM

Very Cool!
Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1