Domain Empire

PHP Beginners Guide

Spaceship Spaceship
Watch
Impact
23
PHP is a server side language, and its not like javascript which is a client side language.

Section I - Using PHP
You can run PHP in basically 4 differen't ways.

<%
// Code in here
%>

<script language="php">
// Code in here
</script>

<?
// Code in here
?>

<?php
// Code in here
?>

I prefer the last method "<?php". You also may see "<?" be called shorttags.

Section II - Comments
There are bascically two ways that I do comments within the PHP code, they are:

<?php
// This is a comment
?>

<?php
/* Comment Line 1
Comment Line 2
*/
?>

As you probably can tell, the /* */ combo provides a multi line commenting system, while // privides a single line comment.

Section III - Display HTML
There are two very common ways to display text/html onto the webpage, print and echo. I prefer echo over print.
Example Usage:
print "<b>This is my bold text</b>";
echo "<b>This is my bold text</b>";

You might notice the ; symbol after those lines, its required after every line that you process data.

Section IV - Variables
Heres an example of giving a variable a value:
$name = "Jon";
And using what you learned earier try making it say on the screen:
Your name is Jon

To display variables in echo's or print's do this:
echo "Your name is $name";
or
echo "Your name is " . $name;

Thanks for reading and I hope it helps. Please remember that this is only a Beginning Guide to some simple features of PHP.

Stay tuned in the future for Tutorial #2 that will have how to do some more features.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Quick to the point, nice job.
 
0
•••
thanks! for starting php u cant have too much :D
 
0
•••
echo "Your name is " . $name;

Can also be written

echo "Your name is ".$name;

echo "Your name is ",$name;

If you must I suggest the comma as it's marginaly faster than the period.
But echo "Your name is $name"; works fastest.

Thought this would be good to add.
 
0
•••
just a quick note regarding the following style tags

<%
// Code in here
%>

<script language="php">
// Code in here
</script>

these may not necessarily as they have to be enabled first however <?php ?> should always work.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back