Question about PHP Pages and Extensions

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
Audioicon
Forum Newbie
Posts: 12
Joined: Thu Aug 14, 2008 12:11 am

Question about PHP Pages and Extensions

Post by Audioicon »

I'm a confused. This is what I know so far. If you are saving a PHP page you need to add the PHP extension. Eg: index.php
Well,you can also embed PHP into HTML/XHTML but what extension do you use?

So if I create an XHTML/HTML page and had several php syntax/codes embeded into the page, will I need to save the page with an html or php extension?

PHP is a dynamic page right? You cannot preview PHP pages in a browser with out a server, t's a server side scripting language. So I need to hook up a local server on my computer like APACHE.

Let say I create an entire page with html but within that page I have a form I built using php?
How would I save this page? What would happen if I view this page in a regular browser? Will I only be able to see the HTML side?

Thanks for you help.

Patrick
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Question about PHP Pages and Extensions

Post by Christopher »

If it has PHP in it then it needs a .php extension. Did you try this yourself? There are only four possible combinations!
(#10850)
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Question about PHP Pages and Extensions

Post by desmi »

Just like Everah puts it:

http://www.robert-gonzalez.com/2007/06/ ... developer/

You dont really need our help to solve your question, you can try it out, thats the best way to learn too.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Question about PHP Pages and Extensions

Post by califdon »

Those responses are surely appropriate, but I can also see that beginners are confused by the very nature of how a preprocessor like PHP works. Therefore, I'll try to explain it for this requestor.

You're correct in your understanding of a server-side script, what you are missing is how it is actually processed by the web server. The server needs to know whether a file NEEDS to be preprocessed, and the common way to do that is by configuring the server to look at the file extension. That is how nearly all web servers are configured, although it is possible to tell a server to parse every file for PHP code. I'm sure you can see that in most installations that would be a lot of wasted cpu cycles. So the normal configuration is that Apache or whatever other web server we're talking about will only parse files for preprocessing if they have a .php extension. No doubt you can figure out the answers to the rest of your questions, once you understand what is going on.
Audioicon
Forum Newbie
Posts: 12
Joined: Thu Aug 14, 2008 12:11 am

Re: Question about PHP Pages and Extensions

Post by Audioicon »

califdon wrote:Those responses are surely appropriate, but I can also see that beginners are confused by the very nature of how a preprocessor like PHP works. Therefore, I'll try to explain it for this requestor.

You're correct in your understanding of a server-side script, what you are missing is how it is actually processed by the web server. The server needs to know whether a file NEEDS to be preprocessed, and the common way to do that is by configuring the server to look at the file extension. That is how nearly all web servers are configured, although it is possible to tell a server to parse every file for PHP code. I'm sure you can see that in most installations that would be a lot of wasted cpu cycles. So the normal configuration is that Apache or whatever other web server we're talking about will only parse files for preprocessing if they have a .php extension. No doubt you can figure out the answers to the rest of your questions, once you understand what is going on.
Thanks for you effort in answering my questions. I did read the response above, one day I'll have my own forum, it's just a matter of having the time to set one up. And people will not get scolded for asking questions, in fact, I'll strongly encourage people to asked anything.

I'm a professional audio engineer and I never try to insult or scold anyone if they need help or answers. If somebody asked a question about Mics, I'm not going to say, "just plug it and listen." If I don't want to answer someone's question, I'll just leave it alone.

But I'm not going to sit there because I know it all and got all my coding knowledge at birth and needed no one to help, so now I can take the time to scold someone for asking question in a place that is suppose to encourage people.

I'm sure there are many PHP resources out there, don't have to come here and put up with know it all attitudes.
Remember when I started learning CSS, had the same attitudes, now I know all I need to know to create a professional CSS/XHTML page. Now I take the time to help other people without scolding them.

Patrick
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Question about PHP Pages and Extensions

Post by EverLearning »

We're not scolding you. We're helping you grow.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Question about PHP Pages and Extensions

Post by desmi »

Im sorry if you feel you got scolded, i was just telling you to test it by yourself, i'm happy to help you with anything, but i really think its much better for learning if you try to solve things first by yourself, then ask help if you cant solve it.
Post Reply