php-general Digest 3 Jan 2011 12:28:21 -0000 Issue 7113

Topics (messages 310450 through 310460):

Re: Newbie Question
        310450 by: Ashley Sheridan
        310451 by: Joshua Kehn
        310452 by: admin.buskirkgraphics.com
        310453 by: Joshua Kehn
        310454 by: Adam Richardson
        310455 by: Joshua Kehn
        310456 by: Adolfo Olivera
        310457 by: Joshua Kehn
        310458 by: Larry Garfield
        310459 by: David McGlone
        310460 by: Ashley Sheridan

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2011-01-02 at 11:48 -0500, [email protected] wrote:

> Add this to your .htaccess file and HTML files will be handled like PHP
> files allowing you put PHP in HTML files.
> 
> AddType application/x-httpd-php .html
> 
> 
> Richard L. Buskirk
> 
> -----Original Message-----
> From: Adolfo Olivera [mailto:[email protected]] 
> Sent: Saturday, January 01, 2011 8:38 PM
> To: Joshua Kehn
> Cc: [email protected]; [email protected]
> Subject: Re: [PHP] Newbie Question
> 
> Sorry, here is the code. The .php extension is a requirement? Can't it b
> embedded on a .html file?
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> <html xmlns="
> http://www.w3.org/1999/xhtml";> <head> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" /> <title>Untitled Document</title>
> </head> <body> <?php $a = "hello"; $hello ="Hello Everyone"; echo $a; echo
> $hello; ?> </body> </html>
> On Sat, Jan 1, 2011 at 9:55 PM, Joshua Kehn <[email protected]> wrote:
> 
> > On Jan 1, 2011, at 7:50 PM, David Robley wrote:
> > >
> > > And normally would need to be saved as a .php file so the contents will
> > be
> > > handled by php.
> > >
> > >
> > > Cheers
> > > --
> > > David Robley
> > >
> > > A fool and his money are my two favourite people.
> > > Today is Boomtime, the 2nd day of Chaos in the YOLD 3177.
> >
> > Save the code as hello.php. Copy it to your root web directory (should be
> > the base directory or something called public_html / www when you FTP in)
> > and access it from youdomain.com/hello.php
> >
> > Regards,
> >
> > -Josh
> > ____________________________________
> > Joshua Kehn | [email protected]
> > http://joshuakehn.com
> >
> >
> 
> 
> -- 
> Adolfo Olivera
> 15-3429-9743
> 
> 


It's really best not to think about embedding PHP in an HTML file, as
that isn't really how it works and it just encourages bad practices.
HTML is embedded inside PHP files, not the other way around. The PHP
parser interprets all the PHP code and creates the necessary output, and
passes that output along with any HTML to the web server to then deliver
to the client (browser). If you embedded PHP inside HTML files, the web
server would have to call up the PHP parser every time you broke in and
out of PHP tags, which wouldn't do at all!

I wouldn't recommend having .html parsed as PHP though, as it will slow
down your website/application unnecessarily for any .html files that
contain no PHP code, as PHP still has to parse the file for any code,
even if there is none. Leave .html files for static pages that you
produce with a PHP app for example, or use MOD_REWRITE to reference PHP
scripts when certain .html files are requested by the browser, as this
can be a whole lot more specific and selective and won't introduce
problems later on.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Jan 2, 2011, at 11:48 AM, <[email protected]> wrote:

> Add this to your .htaccess file and HTML files will be handled like PHP
> files allowing you put PHP in HTML files.
> 
> AddType application/x-httpd-php .html
> 
> 
> Richard L. Buskirk
> 

I would not recommend this approach, some perfectly valid reasons given by Ash. 
It's the wrong mindset to have.

Regards,

-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com



--- End Message ---
--- Begin Message ---
The question was "The .php extension is a requirement?"

The answer is no.

While me and Ash may completely disagree on the php parser, the simple answer 
is there are many ways around running a non .php extension file in php.


mod_rewrite rules in .htaccess files are interpreted for each request and CAN 
slow down things if your traffic is high.

Having said that, mod_rewrite in httpd.conf is faster because it is compiled at 
server restart and it is native to the server.

As a beginner, I completely agree with ash on bad practice rule of thumb. You 
will simply rewrite the html file later on wishing you had never did the hack 
to make it function. 







Richard L. Buskirk

-----Original Message-----
From: Ashley Sheridan [mailto:[email protected]] 
Sent: Sunday, January 02, 2011 12:16 PM
To: [email protected]
Cc: 'Adolfo Olivera'; 'Joshua Kehn'; [email protected]; 
[email protected]
Subject: RE: [PHP] Newbie Question

On Sun, 2011-01-02 at 11:48 -0500, [email protected] wrote:

> Add this to your .htaccess file and HTML files will be handled like PHP
> files allowing you put PHP in HTML files.
> 
> AddType application/x-httpd-php .html
> 
> 
> Richard L. Buskirk
> 
> -----Original Message-----
> From: Adolfo Olivera [mailto:[email protected]] 
> Sent: Saturday, January 01, 2011 8:38 PM
> To: Joshua Kehn
> Cc: [email protected]; [email protected]
> Subject: Re: [PHP] Newbie Question
> 
> Sorry, here is the code. The .php extension is a requirement? Can't it b
> embedded on a .html file?
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> <html xmlns="
> http://www.w3.org/1999/xhtml";> <head> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8" /> <title>Untitled Document</title>
> </head> <body> <?php $a = "hello"; $hello ="Hello Everyone"; echo $a; echo
> $hello; ?> </body> </html>
> On Sat, Jan 1, 2011 at 9:55 PM, Joshua Kehn <[email protected]> wrote:
> 
> > On Jan 1, 2011, at 7:50 PM, David Robley wrote:
> > >
> > > And normally would need to be saved as a .php file so the contents will
> > be
> > > handled by php.
> > >
> > >
> > > Cheers
> > > --
> > > David Robley
> > >
> > > A fool and his money are my two favourite people.
> > > Today is Boomtime, the 2nd day of Chaos in the YOLD 3177.
> >
> > Save the code as hello.php. Copy it to your root web directory (should be
> > the base directory or something called public_html / www when you FTP in)
> > and access it from youdomain.com/hello.php
> >
> > Regards,
> >
> > -Josh
> > ____________________________________
> > Joshua Kehn | [email protected]
> > http://joshuakehn.com
> >
> >
> 
> 
> -- 
> Adolfo Olivera
> 15-3429-9743
> 
> 


It's really best not to think about embedding PHP in an HTML file, as
that isn't really how it works and it just encourages bad practices.
HTML is embedded inside PHP files, not the other way around. The PHP
parser interprets all the PHP code and creates the necessary output, and
passes that output along with any HTML to the web server to then deliver
to the client (browser). If you embedded PHP inside HTML files, the web
server would have to call up the PHP parser every time you broke in and
out of PHP tags, which wouldn't do at all!

I wouldn't recommend having .html parsed as PHP though, as it will slow
down your website/application unnecessarily for any .html files that
contain no PHP code, as PHP still has to parse the file for any code,
even if there is none. Leave .html files for static pages that you
produce with a PHP app for example, or use MOD_REWRITE to reference PHP
scripts when certain .html files are requested by the browser, as this
can be a whole lot more specific and selective and won't introduce
problems later on.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--- End Message ---
--- Begin Message ---
On Jan 2, 2011, at 12:50 PM, <[email protected]> wrote:

> The question was "The .php extension is a requirement?"
> 
> The answer is no.
> 
> While me and Ash may completely disagree on the php parser, the simple answer 
> is there are many ways around running a non .php extension file in php.
> 
> 
> mod_rewrite rules in .htaccess files are interpreted for each request and CAN 
> slow down things if your traffic is high.
> 
> Having said that, mod_rewrite in httpd.conf is faster because it is compiled 
> at server restart and it is native to the server.
> 
> As a beginner, I completely agree with ash on bad practice rule of thumb. You 
> will simply rewrite the html file later on wishing you had never did the hack 
> to make it function. 
> 
> Richard L. Buskirk

> Sorry, here is the code. The .php extension is a requirement? Can't it b 
> embedded on a .html file?

_This_ question when asked from a beginner requires a non-confusing answer of 
"yes." 

> Can't it be embedded on a .html file?

PHP is always embedded alongside HTML code within <?php ?> tags. It's not 
embedded inside a .html file as the extension should indicate the file type. 
Adding a mod_rewrite rule (as you suggest) can lead to confusion later on in 
development. At the very least you'll look stupid re-asking "Can't it be 
embedded..." 

Regards,

-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com




--- End Message ---
--- Begin Message ---
On Sun, Jan 2, 2011 at 12:16 PM, Ashley Sheridan
<[email protected]>wrote:

> On Sun, 2011-01-02 at 11:48 -0500, [email protected] wrote:
>
> > Add this to your .htaccess file and HTML files will be handled like PHP
> > files allowing you put PHP in HTML files.
> >
> > AddType application/x-httpd-php .html
> >
> >
>
I wouldn't recommend having .html parsed as PHP though, as it will slow
> down your website/application unnecessarily for any .html files that
> contain no PHP code, as PHP still has to parse the file for any code,
> even if there is none. Leave .html files for static pages that you
> produce with a PHP app for example, or use MOD_REWRITE to reference PHP
> scripts when certain .html files are requested by the browser, as this
> can be a whole lot more specific and selective and won't introduce
> problems later on.
>


I tend to disagree with Ashley on this topic.  For many websites, I'll start
out making all pages .php, even if they don't require PHP at the moment.
 That's for a couple reasons.

1) A few years back, there was certainly a significant performance advantage
to keeping essentially static pages html.  However, in my current
benchmarking (using both siege and ab on my Ubuntu servers using apache with
mod_php), if I use a cache such as APC and a well-configured apache server,
PHP tends to perform just as well (or sometimes even better) than the html
version.

Rasmus has demonstrated similar performance results:
http://talks.php.net/show/froscon08/24

2) I don't want to have to change urls site-wide and set up redirects from
the old url whenever a page requires adding dynamic capabilities.  By making
all pages PHP right from the beginning, adding dynamic capabilities is a
snap as I just add the functionality.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Jan 2, 2011, at 1:17 PM, Adam Richardson wrote:
> 
> I tend to disagree with Ashley on this topic.  For many websites, I'll start
> out making all pages .php, even if they don't require PHP at the moment.
> That's for a couple reasons.
> 
> 1) A few years back, there was certainly a significant performance advantage
> to keeping essentially static pages html.  However, in my current
> benchmarking (using both siege and ab on my Ubuntu servers using apache with
> mod_php), if I use a cache such as APC and a well-configured apache server,
> PHP tends to perform just as well (or sometimes even better) than the html
> version.
> 
> Rasmus has demonstrated similar performance results:
> http://talks.php.net/show/froscon08/24
> 
> 2) I don't want to have to change urls site-wide and set up redirects from
> the old url whenever a page requires adding dynamic capabilities.  By making
> all pages PHP right from the beginning, adding dynamic capabilities is a
> snap as I just add the functionality.
> 
> Adam

I agree starting with all .php files is good practice for basic sites. I 
recommend for applications and bigger then basic project using a decent 
framework or main routing file to handle routes for you, instead of requiring 
you to manually adjust them if something changes.

Regards,

-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
Thanks for the replies. I'll just put a php on all my html containing php.
A little of topic. Wich IDE are you guys using. I'm sort of in a catch
twenty two here. I been alternating vim and dreamweaver. I'm trying to go
100% open source, but I really find dreamweaver easier to use so far.

El ene 2, 2011 3:25 p.m., "Joshua Kehn" <[email protected]> escribió:

On Jan 2, 2011, at 1:17 PM, Adam Richardson wrote:
>
> I tend to disagree with Ashley on this topic...
I agree starting with all .php files is good practice for basic sites. I
recommend for applications and bigger then basic project using a decent
framework or main routing file to handle routes for you, instead of
requiring you to manually adjust them if something changes.


Regards,

-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshu...

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
On Jan 2, 2011, at 5:56 PM, Adolfo Olivera wrote:
> Thanks for the replies. I'll just put a php on all my html containing php.
> A little of topic. Wich IDE are you guys using. I'm sort of in a catch twenty 
> two here. I been alternating vim and dreamweaver. I'm trying to go 100% open 
> source, but I really find dreamweaver easier to use so far.
> 

I use VIM and TextMate exclusively. 

Regards,

-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com


--- End Message ---
--- Begin Message ---
On Sunday, January 02, 2011 4:56:28 pm Adolfo Olivera wrote:
> Thanks for the replies. I'll just put a php on all my html containing php.
> A little of topic. Wich IDE are you guys using. I'm sort of in a catch
> twenty two here. I been alternating vim and dreamweaver. I'm trying to go
> 100% open source, but I really find dreamweaver easier to use so far.

I bounce between NetBeans and Eclipse, depending on which currently sucks 
less.  I have yet to find a PHP IDE that doesn't suck; it's just degrees of 
suckage. :-)

--Larry Garfield

--- End Message ---
--- Begin Message ---
On Sunday, January 02, 2011 08:43:51 pm Larry Garfield wrote:
> On Sunday, January 02, 2011 4:56:28 pm Adolfo Olivera wrote:
> > Thanks for the replies. I'll just put a php on all my html containing
> > php. A little of topic. Wich IDE are you guys using. I'm sort of in a
> > catch twenty two here. I been alternating vim and dreamweaver. I'm
> > trying to go 100% open source, but I really find dreamweaver easier to
> > use so far.
> 
> I bounce between NetBeans and Eclipse, depending on which currently sucks
> less.  I have yet to find a PHP IDE that doesn't suck; it's just degrees of
> suckage. :-)

I use Kate. It doesn't suck at all because it doesn't try to do the coding for 
you :-)

-- 
Blessings
David M.

--- End Message ---
--- Begin Message ---
On Sun, 2011-01-02 at 21:10 -0500, David McGlone wrote:

> On Sunday, January 02, 2011 08:43:51 pm Larry Garfield wrote:
> > On Sunday, January 02, 2011 4:56:28 pm Adolfo Olivera wrote:
> > > Thanks for the replies. I'll just put a php on all my html containing
> > > php. A little of topic. Wich IDE are you guys using. I'm sort of in a
> > > catch twenty two here. I been alternating vim and dreamweaver. I'm
> > > trying to go 100% open source, but I really find dreamweaver easier to
> > > use so far.
> > 
> > I bounce between NetBeans and Eclipse, depending on which currently sucks
> > less.  I have yet to find a PHP IDE that doesn't suck; it's just degrees of
> > suckage. :-)
> 
> I use Kate. It doesn't suck at all because it doesn't try to do the coding 
> for 
> you :-)
> 
> -- 
> Blessings
> David M.
> 


Kate is good for basic editing, but I use NetBeans for my main
development, as I like the code hinting it gives you for your own class
and function definitions. Incidentally, you can get Kate working on
Windows if you install KDE on it, which I do at work. It gives me a
setup similar to what I'm most used to at home with my Linux box.

I'd avoid DreamWeaver whatever you do. Unless it's been severely
improved recently, it's not a serious developers tool, more of an
expensive hobbyists. It tries to hint and help too much, which really
gets in the way when you're trying to write code and you know what
you're doing!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---

Reply via email to