RadiantEclipseForums II
Hello, Guest! Very Happy Welcome To RadiantEclipseForums, If You Haven't Already Please Register Smile
RadiantEclipseForums II
Hello, Guest! Very Happy Welcome To RadiantEclipseForums, If You Haven't Already Please Register Smile



 
HomeSearchLatest imagesRegisterLog in
REF Now Has A Twitter And A Facebook Fan Page! Go Follow @RadiantEForums, And Like RadiantEclipseForums on Facebook!

Share | 
 

 PHP Tutorial Part 2

View previous topic View next topic Go down 
AuthorMessage
Dumbledore27
Admin
Admin
Dumbledore27

Posts : 337
Points : 6081
Reputation : 13
Join date : 2011-10-01
Age : 24
Location : In a dictionary, under 'A'.

PHP Tutorial Part 2 Empty
PostSubject: PHP Tutorial Part 2   PHP Tutorial Part 2 EmptyWed Dec 07, 2011 11:48 am

Welcome to already the second part of my PHP tutorials. Smile

Today, we will take a look at the variables. A variable in PHP begins with a dollar sign ($).

A variable to be used must first be defined. We will define the variable "ref" and then echo it (see my tutorial on echo).
Code:
<?php
$ref = "Radiant Eclipse Forums";
echo "Welcome to $ref!<br />";
echo "Welcome to " . $ref . "!";
?>
That would output:
Quote :
Welcome to Radiant Eclipse Forums!
Welcome to Radiant Eclipse Forums!
(Note: the "br" tag is line-break. Otherwise it would render on the same line.)

With forms, we can also use the information user entered (we will need one HTML file and another PHP file to process what they entered - we could use if (empty || !isset(...)), but that wouldn't be basic any more).

The HTML page:
Code:
<form action="name.php" method="post">
Your Name:<br />
<input type="text" value="" name="name" /><br /><br />
Age:<br />
<input type="text" name="age" /><br />
<input type="submit" value="Send!" /></form>
Change "name.php" to match the name of the PHP file.

And now the PHP file:
Code:
<?php
//First, we define "name" and "age" variables.
//You can skip this and use $_POST variables.
$name = $_POST['name'];
$age = $_POST['age'];
echo "Hello $name! You are $age years old.";
Here is an example of what this would output:
Quote :
Hello Bryan! You are 13 years old.

MUST REMEMBERs about variables:
A variable must not start with a number ($0cash is invalid).
A variable can only contain alphanumeric characters and underscores (A-Z, a-z, 0-9, _). It can't have any non-English characters such as č, š, ž, ü, ä etc.
A variable cannot contain spaces. Variables, such as $my car are not valid. The words must be separated by capitalization ($myCar) or by underscore ($my_car) or not separated at all ($mycar).
Variables are case sensitive: $ref is not the same as $Ref or $REF.

_____

We will also take a look at strings or what you can do with Echo.

In my previous tutorial, we did a basic echo code.
Code:
<?php
echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida.";
?>
There are several functions we can use. It would take a very long time to write all of them, so I'm referencing some of them.

Character Count
Using the strlen function, PHP will write the number of characters in a string (with spaces). Example:
Code:
<?php
echo strlen("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida.");
?>
gives us
Quote :
71

Locate the word
Using the strpos function, we can establish how many characters are before a certain word. For example:
Code:
<?php
echo strpos("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec gravida.","amet");
?>
This will output "22".

Encode
The most popular encoding is MD5. Many forums, including this one (unless Forumotion guys got us screwed) use it. It's often used to encrypt passwords and cannot be decrypted. In theory. There are many decrypters, but it SHOULDN'T be possible to decrypt it. We will use a simple md5 function:
Code:
<?php
echo md5("REF is awesome!");
?>

That text gets encrypted as:
758776a0f2ae2370b182669e5d01aad2

Be sure to use this (or any other encoding that can be accessed directly through PHP) whenever you store passwords in a database. If someone hacks into your database, the encryption is no good to them.

Stay tuned for more!
Back to top Go down
http://www.myvocabtionary.co.cc
Dumbledore27
Admin
Admin
Dumbledore27

Posts : 337
Points : 6081
Reputation : 13
Join date : 2011-10-01
Age : 24
Location : In a dictionary, under 'A'.

PHP Tutorial Part 2 Empty
PostSubject: Re: PHP Tutorial Part 2   PHP Tutorial Part 2 EmptySat Jan 14, 2012 6:28 am

Anybody still interested in the tutorials so I know if I should continue? Smile
Back to top Go down
http://www.myvocabtionary.co.cc
Fiction
Founder
Founder
Fiction

Posts : 903
Points : 2147483647
Reputation : 36
Join date : 2011-10-01
Age : 26
Location : A Place of Hope And No Pain

PHP Tutorial Part 2 Empty
PostSubject: Re: PHP Tutorial Part 2   PHP Tutorial Part 2 EmptySat Jan 14, 2012 8:39 pm

If There's A part 3 Keep Going I Like Reading These c:
Back to top Go down
https://radianteclipseforums.forumotion.net
Jack
Moderator
Moderator
Jack

Posts : 88
Points : 102
Reputation : 7
Join date : 2012-01-02
Age : 26
Location : England

PHP Tutorial Part 2 Empty
PostSubject: Re: PHP Tutorial Part 2   PHP Tutorial Part 2 EmptySat Jan 14, 2012 8:54 pm

Me to, shame I can't get PHP to work though Sad
Back to top Go down
http://jhgamesforums.forumotion.co.uk/
Sponsored content




PHP Tutorial Part 2 Empty
PostSubject: Re: PHP Tutorial Part 2   PHP Tutorial Part 2 Empty

Back to top Go down
 

PHP Tutorial Part 2

View previous topic View next topic Back to top 

 Similar topics

-
» PHP Tutorial Part 1
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
RadiantEclipseForums II :: Fun :: Coding :: Tutorials-
Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com