What's Here?
- Members: 307,175
- Replies: 841,965
- Topics: 140,717
- Snippets: 4,468
- Tutorials: 1,165
- Total Online: 1,582
- Members: 95
- Guests: 1,487
|
Loading. Please Wait... 
Replies(1 - 19)
| pr4y |
RE: PHP To HTML
20 Feb, 2009 - 11:56 AM
|

Location: 127.0.0.1

Joined: 19 Sep, 2008
Posts: 615
Thanked: 29 times
Dream Kudos: 175
My Contributions
|
Also, if you need PHP to deliver dynamic content based on the user's actions.. you could do the following: php <?php $switch = $_GET['page'];
if (isset($switch)){ switch ($switch) { case 1: page1(); break; case 2: page2(); break; } } else { defaultPage(); }
function page1(){ // Deliver page 1 content } function page2(){ // Deliver page 2 content } function defaultPage(){ // Deliver default page content }
OR php <?php $switch = $_GET['page'];
if (isset($switch)){ switch ($switch) { case 1: ?> <!-- HTML Code Here --> <?php break; case 2: ?> <!-- HTML Code Here --> <?php break; } } else { ?> <!-- HTML Code Here --> <?php } ?>
As you can see, with this you could build an entire website off of 1 file. It is not recommended to do this, I just wanted to demonstrate PHP's ability to deliver totally dynamic content to the end user. I hope we've been helpful! This post has been edited by pr4y: 20 Feb, 2009 - 11:58 AM
|
|
|
|
| CTphpnwb |
RE: PHP To HTML
20 Feb, 2009 - 11:57 AM
|

D.I.C Lover

Joined: 8 Aug, 2008
Posts: 2,101
Thanked: 155 times
Dream Kudos: 100
Expert In: PHP
My Contributions
|
QUOTE(girasquid @ 20 Feb, 2009 - 02:49 PM)  Personally, I wouldn't have PHP be responsible for outputting anything more than is absolutely necccessary:
But that tends to end up more like this: CODE <?php // prints headers, assigns variables, does calculations, etc. ?> <html> <head> <title><?php echo $var1 ?></title> </head> <body> Some text <?php echo $var2 ?> and some more text <?php echo $var3 ?> and some more.... ... ...<?php echo $varN-1 ?>
You are visitor number: <?php echo $varN ?> </body> </html>
Which is ok I suppose, if you don't mind putting everything into one array for output. This post has been edited by CTphpnwb: 20 Feb, 2009 - 11:58 AM
|
|
|
|
| girasquid |
RE: PHP To HTML
22 Feb, 2009 - 01:16 PM
|

Barbarbar

Joined: 3 Oct, 2006
Posts: 1,648
Thanked: 58 times
Dream Kudos: 825
My Contributions
|
QUOTE(CTphpnwb @ 20 Feb, 2009 - 11:57 AM)  But that tends to end up more like this: CODE snip
Which is ok I suppose, if you don't mind putting everything into one array for output. The nice thing about most programming languages is that there's more than one way to do it - typically when I've done this, I've just given the variables meaningful names like $visitors, instead of dumping it all into an array. Everybody's different, though.
|
|
|
|
| no2pencil |
RE: PHP To HTML
22 Feb, 2009 - 06:41 PM
|

i R L33t Skiddie, k?

Joined: 10 May, 2007
Posts: 13,499
Thanked: 303 times
Dream Kudos: 2875
Expert In: Goofing Off
My Contributions
|
QUOTE(kumaraj @ 20 Feb, 2009 - 11:56 AM)  Do I create a HTML file and add PHP straight to it like this?
Because PHP runs on the server, it cannot simply be included in the html code. The html code is executed by the clients browser, where PHP code does not exist. [server] -> [internet] -> [ISP] -> [Browser] PHP Code is executed -> prepares HTML -> Displayed by clients browser
|
|
|
|
| kumaraj |
RE: PHP To HTML
23 Feb, 2009 - 05:12 AM
|

New D.I.C Head

Joined: 12 Feb, 2009
Posts: 9
|
Thanks Guys! kumaraj here again. If I use any of these codes would I then save these files as file.phpOR file.htmlPlease help I am completely new to PHP and as I said I am unable to download any software.
|
|
|
|
| kumaraj |
RE: PHP To HTML
25 Feb, 2009 - 05:53 AM
|

New D.I.C Head

Joined: 12 Feb, 2009
Posts: 9
|
QUOTE(girasquid @ 23 Feb, 2009 - 06:02 PM)  You'd save them as .php.
Ok. Can IE then open this file if I use Notepad?
|
|
|
|
| chris.ballard |
RE: PHP To HTML
25 Feb, 2009 - 10:57 AM
|

New D.I.C Head

Joined: 25 Feb, 2009
Posts: 14
My Contributions
|
QUOTE(girasquid @ 23 Feb, 2009 - 06:02 PM)  You'd save them as .php.
This is only true by default if you are using php4 or newer (which you probably are  ). You also do not have to name your files .php if you configure your webserver. I have all of mine named .html for ambiguity. If you wish to change your extension and you are using apache you can simply make your AddType (in httpd.conf) look like this: CODE AddType application/x-httpd-php .php .html then all you have to do is restart apache and you now have .html registerd as a php extension. Just as a note this does not prevent you from using .html as a strait html file, it just passes the file through the interpreter.
|
|
|
|
| KuroTsuto |
RE: PHP To HTML
25 Feb, 2009 - 06:03 PM
|

D.I.C Head

Joined: 13 Feb, 2009
Posts: 104
Thanked: 12 times
Dream Kudos: 25
My Contributions
|
I love how insanely complex this little intro to PHP thread just got  . I think I'll ad a lil complexity by restating everything that's been said in my own manner, one which I hope will clear things up a little. HTML is, in essence, a language that strictly dictates structure and display. It is responsible for how a website is organized, as well as what elements (tables, borders, text, etc.) are what color and essentially where they are. It is then the job of the user's browser (IE, Firefox, etc.) to interpret the HTML and display it correctly. PHP, on the other hand, is a language that handles logic. While it is true that PHP code is commonly placed in the same document as HTML, when the user requests a file with PHP, the webserver first processes all of the PHP within the file, displaying any additional content that a PHP function tells it to (i.e. the "echo" function essentially passes the content of its argument into the html document*), and then sends the resulting client-side info (i.e. HTML, Javascript, CSS etc.) to the user who originally requested the file. In this sense, while said user did indeed request a page containing PHP code, the page that they actually receive does not contain any PHP code to speak of. So files with PHP code MUST first pass through a server with PHP installed upon it to function properly, else if you were to open a PHP file on a computer not set up to interpret such code (the vast majority of computers in the world), you would likely see all of the actual code displayed as though it were nothing more than plain text. To be a little bit more specific about how a server interprets such a file containing both HTML and PHP code, the "<?php" and "?>" tags tell the server where to start and stop processing PHP. Anything inside of those tags will be processed as PHP, and anything outside of them will (in the majority of cases) be left ignored. Hopefully this clears up some of the examples the others have given you. As for the thing about naming such files with a ".php" extension, I will tell you that by default, most webservers will indeed interpret such a file as one containing PHP by default. This is the safest bet. Or, if you would like to get more advanced and you have access to a webserver or some server install on your own machine, you can, as chris.ballard stated, modify the configuration of the server to use different extensions. If you're really interested in learning PHP, I will tell you that I first began learning the language from the brief tutorial/overview at the w3schools.com website. Cheers! ~KuroTsuto
|
|
|
|
|
|