Re: [PHP] Couple of beginner questions



At 8:48 AM -0500 1/10/09, Gary wrote:
Looks like a great link, thank you.

But am I to understand that all I need to do is change the extention on a
file to php from html for all to be right with the world?

Yup.

By changing the suffix (extension), you are telling the server that this file is to be treated differently than a html file. As such, the php interpreter will process the file before it is sent to the browser.

A statement like:

<?php echo('Hello'); ?>

Will print "Hello" to the browser. In fact, the browser will never see your php code unless you make a mistake. The file will be processed and delivered to the browser as html.

Please note that my use of echo above does not require the (), that's a habit I practice for no good reason whatsoever other than I like it. I think it's because I'm dyslectic and it makes sense to me.

In any event, I would consider the following"bad practice":

<?php echo('<h1>Hello</h1>'); ?>

Whereas, the following I would consider "good practice".

<h1><?php echo('Hello'); ?></h1>

As best as you can, try to keep php and html separate.

I know that some have different ideas on "good/bad" practices, but you'll develop your own views/habits as you grow and learn.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
.



Relevant Pages

  • Re: How do we get there from here?
    ... Unlike my dislike for PHP, my dislike for SQL is based on ... >>> up with at least html and php quite mixed into each other, ... Using a PHP script to send HTML ... code to a browser in no way taints that code. ...
    (comp.databases.pick)
  • Re: Form spam? What to do?
    ... >>> You will notice a php include at the top of the code. ... one example of a browser with such an Accept ... On contrast IE6 accepts the html 4.01 strict code as you can ... it has built in changes to process the true xhtml ...
    (alt.html)
  • Re: Browser Compatibility issues
    ... PHP is not the cause. ... PHP just outputs HTML ... browser and which features are implemented and which not differs per ...
    (comp.lang.php)
  • Re: [PHP] eof bof in php
    ... Anthony Gentile wrote: ... it is bad practice to mix PHP and HTML as horridly as I just showed you. ...
    (php.general)
  • Re: doesnt work, how come?
    ... > You need a book on HTML and how it works. ... > output from php source. ... it wouldn't be displayed in a browser but it would sort of break up ... Web browsers interpret ASCII text by the rules of HTML. ...
    (alt.php)