NamePros.Com (http://www.namepros.com/)
-   Webmaster Tutorials (http://www.namepros.com/webmaster-tutorials/)
-   -   PHP Beginners Guide (http://www.namepros.com/webmaster-tutorials/38763-php-beginners-guide.html)

ninedogger 07-14-2004 10:05 AM

PHP Beginners Guide
 
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.

Ethan 07-14-2004 06:49 PM

Quick to the point, nice job.

killaklown 09-02-2004 07:16 PM

thanks! for starting php u cant have too much :D

ToddW 10-25-2004 01:35 AM

Quote:
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.

Peter 10-30-2004 11:02 AM

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.


All times are GMT -7. The time now is 03:08 AM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0