Code2Design.com

User login

The Layout

Programming

Graphic Design

Resources

Navigation

C2D Projects

Unsystematic Affiliates

Capital Tutorials N1 Studios Pixel Depth Source Crave 

Change Language

Who's online

There are currently 0 users and 8 guests online.

Lesson 4 - First PHP File

Watch the Movie of Lesson 4

Now we are going to put the topics we disscussed in lessons 1-3 into practice.

When you make a PHP file you have to name it '*.php' (something.php) just like microsoft word documents are named '*.doc' and some images are '*.jpg'. If you don't name a file '*.php' - the PHP core won't process it, and it won't work.

Open up "notepad" (I use/recomend the free SciTE Text Editor becuase it HIGHLIGHTS the different code!)or some other simple text editor(NOT MS WORD, or WORD PERFECT) and type the following:

<?php
$site_name 
"type some site of your own here";
//the $site_name string
$paragraph_text "Type your welcome text here! type more text here!";
// the first $paragraph string
$email 'type your@email.com';
//your email string
$your_age 00;
// your age variable
?>


<html>
<body>
<h2><?php echo $site_name?></h2>
<p><?php echo $paragraph_text?></p>
<p>Email me: <a href="mailto:<?php echo $email?>"><?php echo $email?></a>
</body>
</html>

Once you are finished typing the text above, select "file", "Save as" and name it "test.php" with the quotes. By naming a file with quotes you are telling the computer not to name it something ".txt". For example, if you just name it test.php (without the quotes) and save it, when you go to the file it will be named "test.php.txt"!

Now upload the file to your web server (FTP). If you don't know how to use FTP (File Transfer Protocol) to put web pages onto the internet, please read FTP 101 - A Beginner's Guide or An Introduction to FTP and I recommend you use the free SmartFTP client.

If you are using "easyphp", "WAMP", or some other program/server on YOUR computer simply save or move the file to the correct folder (probably "C:\wamp\www\" or something like that.)

Once the file is in the correct place, point your browser to the location of the file and run it. If you are using a web server the file will be wherever you FTP'ed it to. (exmaple: "http://www.yoursite.com/test.php") If you are using a server on your own PC it should be something like "http://localhost/test.php"

when you run the page you should see this:

type some site of your own here
Type your welcome text here! type more text here!
Email me: type

If you hold your mouse over the page and "right-click" and select "view source" from the options - you will see this in the pop-up window:

<html>
<body>
<h2>type some site of your own here</h2>
<p>Type your welcome text here! type more text here!</p>
<p>Email me: <a href="mailto:type ">type </a>
</body>
</html>

Where is all of the PHP code? Well PHP processed it all and then gave the result to the brower. It ran the php code and submitted the result to your computer to display. That is one of the beauties of PHP - No one knows what you type! No one can steal your code (javascript) and no one can "beat the system" by knowing what you are doing behind the scenes on your web site - so you are safer from hackers (As opposed to other languages).

If you want a challenge make a file named "address.php" that prints your address from three different strings: (your name, street, and city/state/zip).

Here is another php file that prints your Full Name:

<?php
$first_name 
"John";
$second_name "M.";
$last_name "Doe";
?>



<html>
<body>
<h2><?php echo "$first_name $second_name $last_name"?></h2>
</body>
</html>

Now that you know what a "string" is - we can start doing some fun things with them!

For more information please read these articles:

Tizag
CodeWalkers - Strings Primer
PHP Manual
Strings Ref
Strings Regular Expressions (Advanced)
Zend - Using Strings

If you find a broken link please let me know, thanks!


Submitted by David on November 9, 2006 - 5:56pm.
printer friendly version

Thank you

Thank you for Lesson 4


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati