mandag 26. september 2011

Utsnitt fra PHP 4 Bible. Tim converse and Joyce Park

PHP is embedded.
PHP is embedded within HTML. In other words, PHP pages are ordinary HTML pages that “escape” into PHP mode only when necessary. Here is an example:

Hi,.
May I call you ?

When a client requests this page, the web server preprocesses it. This means it goes through the page from top to bottom, looking for sections of PHP, which it will try to resolve. For one thing, the parser will suck up all assigned variables (marked by dollar signs) and try to plug them into later PHP commands (in this case, the print () function ). If everything goes smoothly, the preprocessor will eventually return a normal HTML page to the client’s browser, as shown in Figure 1-1.
“Hi. Ms. Hari. May I call you Mata?”
If you peek at the source code from the client browser (select “source” or “page source” from the view menu, or right click on AOL), it will look like this:

Hi, Ms. Hari. May I call you Mata?

This is exactly the same as if you wrote the HTML by hand. So simple!
The HTML-embeddedness of PHP has many helpful consequences:
*PHP can quickly be added to code produced by WYSIWYG editors.
*PHP lends itself to a division of labor between designers and scripters.
*Every line of HTML does not need to be rewritten in a programming language.
*PHP can reduce labor costs and increase efficiency.
PHP isn’t tag-based
PHP is a real programming language. Coldfusion, by contrast, is a bunch of predefined tags, like HTML. In PHP, you can define functions to your heart’s content just by typing a name and a definition. In ColdFusion, you have to use tags developed b other people, or go through the custom tag extension development process. As a witty PHP community member once said, “Coldfusion makes easy things easy, and a medium-hard thing impossible.” And as every programmer will agree: once you experience the power of curly brackets and loops, you never go back to tags.
Summary:
PHP isn’t the panacea for every web development problem, but it has a lot of advantages. It’s built by web developers for web developers and supported by a large and enthusiastic community. It sits on a sweet-spot of lightness, power, reliability, and easy of use. It offers best-of-breed connectivity to backend servers of all types. And did we mention it’s free? To know PHP is to love it for many of the most common Web development tasks have been selected.

Programming versus scripting.
The difference between programming and scripting is being increasingly blurred by recent developments in programming languages. For instance, PHP definitely uses most of the same control structures as other programming languages. However, fully-interpreted HTML-embedded languages such as ASP are still considered to be on the scripting side of the line, whereas separately compiled binaries are a definite mark of programming. But since PHP 4 is now dynamically compiled (the compiled binary is stored and reused until the source code changes), it’s officially a “real” programming language – and don’t let anyone tell you otherwise. This change accounts for much of the screaming speed of PHP 4, which moves into the same class as Perl.

Ingen kommentarer:

Legg inn en kommentar