Get support from Xavier Media
It is currently Sun Dec 08, 2013 12:26 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Lesson 4 - First PHP File
PostPosted: Thu Jul 13, 2006 6:43 pm 

Points:
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' 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]
<?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>
[/php]



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:

Code:
type some site of your own here
Type your welcome text here! type more text here!
Email me: type your@email.com


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:

Code:
<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 your@email.com">type your@email.com</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]
<?php
$first_name = "John";
$second_name = "M.";
$last_name = "Doe";
?>


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

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

Learn PHP Strings Ref

Strings Regular Expressions (Advanced)

Zend - Using Strings

If you find a broken link please PM me, thanks!


Report this post
Top
  
Reply with quote  
 Post subject: 1 Question
PostPosted: Sat Aug 26, 2006 5:24 pm 

Points:
Why do you use <?php ?>

I use <? ?>

Is there any diferences?

Thanks


Report this post
Top
  
Reply with quote  
 Post subject: Re: 1 Question
PostPosted: Sat Aug 26, 2006 7:27 pm 

Points:
LuRsT wrote:
Why do you use <?php ?>

I use <? ?>

Is there any diferences?

Thanks



"<?php" is the UNIVERSAL way to start PHP code - no matter what server your on it will work.

"<?" is short-hand for starting PHP code - you have to enable the feature in your php.ini file. A lot of web servers don't enable it so it doesn't work...


Report this post
Top
  
Reply with quote  
 Post subject: Can I use Frontpage to upload Php
PostPosted: Sat Sep 09, 2006 1:47 pm 

Points:
:-D Can I use Frontpage to upload any php files?


Report this post
Top
  
Reply with quote  
 Post subject: Re: Can I use Frontpage to upload Php
PostPosted: Sat Sep 09, 2006 6:24 pm 

Points:
majesticworks wrote:
:-D Can I use Frontpage to upload any php files?


I don't know :P I have never used a WYSIWYG editor for any of my web sites. But I am sure FrontPage and Dreamwever should have some kind of function for uploading PHP files.

But be careful! They might treat the PHP files like HTML files and add lots of "proper" code to them. (Thereby causing lots of errors).

If you don't know how to upload the files regularly through an "FTP" client, you really should take some time to learn that. Trust me, it is REALY simple...Just like moving/copying/deleting files in a windows folder.

I recommend SmartFTP


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]