my first code how do i view php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dannerz
Forum Newbie
Posts: 10
Joined: Tue Dec 21, 2010 10:14 am

my first code how do i view php?

Post by Dannerz »

I made my first .php document.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Your Title Here </title>
<meta name="Generator" content="Alleycode HTML Editor">
<meta name="Description" content="Your description here...">
<meta name="Keywords" content="Your keywords here...">
</head>

<body>
This is a test.

<?php
echo "Hello World";
?>

</body>
</html>
When I open the document with my browser,
it says "this is a test", but it does not say "Hello World".
I thought both were supposedto be visible.

What do i download so that I can view .php on my computer?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: my first code how do i view php?

Post by twinedev »

To view it on your computer (ie. not actually uploading it to a web server elsewhere), you need to have a local web server to run it on. There are two options.

1. If you just have a windows machine, you can try xampp which does a decent job of installing Apache, mySQL, PHP and Perl to run as a local web server on your machine. (http://www.apachefriends.org/en/xampp.html)

2. If you have a spare system, I'd suggest setting up a system as an actual server running linux. (search for tutials on google, plenty of them)

-Greg
Dannerz
Forum Newbie
Posts: 10
Joined: Tue Dec 21, 2010 10:14 am

Re: my first code how do i view php?

Post by Dannerz »

Thank you for your helpful reply.
I will see what I can download, and if i can't get it to run on my computer,
ill try to find a free server to upload and test files on.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: my first code how do i view php?

Post by califdon »

Just to expand on the reasoning behind this, PHP is a server language, the browser never sees it (hopefully!), so if you merely open a local PHP document in your browser, it's unable to parse the PHP. You have to request the document from a web server (Apache or IIS), which parses the PHP language, does whatever that tells it to do, THEN sends the results to the browser. This is a vital concept to have when you begin working with PHP.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: my first code how do i view php?

Post by social_experiment »

Dannerz wrote:What do i download so that I can view .php on my computer?
If you are running a windows operation system look for XAMPP (as twinedev mentiones), it's easy to install and to use once it has been installed.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: my first code how do i view php?

Post by ScOrPi »

use php designer , it has localhost without installing Apache or camel server
Post Reply