Simply Cutting Edge
Welcome Guest [Log In] [Register]
Welcome to zetaNetwork. We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as viewing zetaNetwork exclusive tutorials and articles, and access to our code snippets section. Registration is simple, fast, and completely free.


Click Here To Register


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
PHP Basics
Topic Started: Apr 16 2011, 10:53 PM (15,877 Views)
Flavius
Member Avatar
Awesome Cool Dude

PHP Basics
Difficulty: Easy
Time: 5 - 10mins



PHP is far easier to learn as opposed to other languages. While it does require knowledge of HTML, it's easier to pick up than Javascript. People ask what it does, well simply put, PHP is the backend of a website. It does the work, while HTML, CSS, and Javascript are all the facade. To have a fully functional dynamic website, you need PHP. If the content is not your own, then you can simply do with Ajax.

Star and Finish:
Code:
 
<?php
// do stuff in here
?>

Let's do something:
Code: HTML
 
<?php
echo "Hello World";
?>

<script type="text/javascript">
document.write("Hello World");
</script>
Here you can see the similarities between PHP and Javascript. In both cases the result would be the text "Hello World". The echo tag is used to output content in the browser. This can be used in a variety of ways to output variables, html, text or anything at all. As you can see, in this case I have used double quotation marks as opposed to single. There is no difference in doing this except when echoing variables. Something you will also find in PHP is that line-breaks will not break the code. While they are not echoed as line breaks, it allows for more structure when coding.

Variables and Echoing:
A variable is defined by the dollar sign in front of its name. It is used in different ways and affects echoing. It does this by changing the way quotation marks are used to define the string. Here is an example of the different quotations marks and how variables are echoed and used in each case.
Code:
 
<?php
$variable = "Simple Echoing of Variable";
echo $variable;
// output = "Simple Echoing of Variable"
// this case uses no quotation marks

$variable = "Variable in a string with SQM";
echo 'This is'.$variable.'and the variable is concatenated';
// output = "This is Variable in a string with SQM and the variable is concatenated"
// the period concatenates the variable to the portions of the string

$variable = "Variable in a string with DQM";
echo "This is $variable";
// output = "This is Variable in a string with DQM"
// this echoes the string of the variable and not the name
?>
This stuffs everything over when you want to echo a variables. It needs to be learned one way and stuck to all the way throughout. The case you choose is dependent on the difficulty and the readability. Some coders will choose one over the other simply because they prefer it. I prefer to use single quotes as I'm used to double quotes for my HTML. This makes it easier for me and everything is in single quotation marks.



Flavius | zetaNetwork Instructor
If you have any questions feel free to PM me or leave the questions bellow.
Offline Profile Quote ^
 
Pro
Member Avatar
Underground Coding

Great introduction to PHP, repped :D
Pro | zetaNetwork Instructor & Admin
I Coded Most Of The Smexy Stuff You See :P
PM Me Any Questions
Need live support? Click here.
Offline Profile Quote ^
 
Quozzo
Member Avatar
Do not fear death for death does not fear you.

indeed, +rep
Posted Image
Offline Profile Quote ^
 
Kitsueki
Member Avatar


Ohhh, so you can include the variable in double quotation marks, but you have to concatenate it with single. Didn't know that, awesome!
Offline Profile Quote ^
 
Flavius
Member Avatar
Awesome Cool Dude

Kitsueki
Apr 19 2011, 05:05 AM
Ohhh, so you can include the variable in double quotation marks, but you have to concatenate it with single. Didn't know that, awesome!
Glad I could help. :D
Offline Profile Quote ^
 
VoidPC
Rules
Getting Into The Groove
1. If I wanted to to declare a variable I must use "$" instead of "var"?
2. document.write() is the same with echo() ?
3. Instead of " + variable + ", we do this? " . $variable . "
Offline Profile Quote ^
 
Pro
Member Avatar
Underground Coding

1. Yes
2. Yes, it is also the same as the print() function in PHP.
3. Yes
Pro | zetaNetwork Instructor & Admin
I Coded Most Of The Smexy Stuff You See :P
PM Me Any Questions
Need live support? Click here.
Offline Profile Quote ^
 
Oracle
Member Avatar
Newbie
Why is there two printing stuff on the screen functions?
Posted Image
Posted Image

Offline Profile Quote ^
 
Pro
Member Avatar
Underground Coding

I made a tutorial just for you :3 http://s4.zetaboards.com/ZetaNetwork/topic/8727668/

Also, sorry, print ins't a function, it's a language construct. I was thinking about Java.
Pro | zetaNetwork Instructor & Admin
I Coded Most Of The Smexy Stuff You See :P
PM Me Any Questions
Need live support? Click here.
Offline Profile Quote ^
 
Oracle
Member Avatar
Newbie
Thank you Pro! <3
Posted Image
Posted Image

Offline Profile Quote ^
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply