PHP Tutorial
|
File and Server Interactions with PHP
As PHP runs on a server, one could argue that every interaction involves files and the server. But the focus in this section of the PHP tutorial is how PHP can be used to read from and write to files and directories. Much of what one used to do with files on the server can better be accomplished by using a database, but working with files is still common and sometimes necessary. The process for interacting with directories is very similar to that for interacting with files, but the data being read or written differs. Any time PHP is used to interact with files, directories, or the server itself, permissions are a frequent cause of problems.
Another subject filed under server interactions with PHP is command-line scripting. This concept is a matter of using PHP outside of a Web browser and without Apache. It's used for the same reasons as shell-scripting (maintenance, routines, creating utilities, etc.), but in PHP. Similar to this, you can use PHP, in conjunction with NuSphere's free PhpDock to create desktop applications without the need for a Web server.
Using Templates in PHP
A Web site template is used to separate the content areas from the presentation. In PHP terms, this largely comes down to separating common HTML elements from page-specific, dynamically-generated content. Using templates in your PHP sites gives them a consistent appearance while also making them easier to maintain. For these reasons, using templates in PHP has become a standard procedure anytime you're dealing with more than a handful of pages.
There are a number of techniques you can use in PHP to template a site. On the simplest end, included files can separate out sections of a Web page (for example, the navigation or copyright area). On the more advanced end of the spectrum, a templating system can be incorporated. Of these, Smarty is the most developed and popular for several reasons:
- Caching improves site performance
- Easy to use
- Extendable in various ways
- Easy to debug
- Secure
One of the negatives of using a template system is that all text editors and most IDEs will not adequately handle the templating system. Fortunately NuSphereâ„¢ PhpED provides excellent support for Smarty, from basic template creation to syntax highlighting (see the figure).
PHP & Web Services
"Web services" is a broad term that's relatively new to the word of computing. A Web service is an established way to transfer data from computer to computer over a network. The premise is not as complicated as it may sound, although actually using Web services in PHP (or any technology) can be a challenge. Similar to using a database application, where PHP requests data stored on the same server (usually), a Web service is a request for data stored remotely. The key to a successful transaction is that all data transmitted back and forth be in the proper format so that it's understandable, and therefore, usable. Web services, therefore, is all about protocols.
Web services is a world of acronyms, the first of which is XML (eXtensible Markup Language). XML was created as a way to share data, primarily across the Internet. XML leads to WSDL (Web Services Description Language). This is a standardized protocol explicitly created for communicating using Web services. WDSL is often used with a third techology, SOAP (which, confusingly enough, used to be an acronym but is no longer). SOAP normally uses HTTP (HyperText Transfer Protocol) to exchange XML-based data over networks.
This may sound like gibberish but what Web services comes down to really is much like interacting with a database. The PHP script needs to know how to ask for the right information from the right resources, and then it can use the returned data. For this purpose, NuSphereâ„¢ PhpED supports NuSOAP, NuSphere's SOAP library, which makes incorporating Web services into applications a snap.
|
Article continues:
<<previous page
next page>>
|
|
Download NuSphere PHP IDE
Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.
|
Buy NuSphere PhpED® now
|
Special Team4 Offer
Get 4 copies of PhpED for the price of 3!
Optimum solution for development teams.
|
|
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
|
|
"To be honest its bloody awesome, I have looked at loads of PHP editors and this is THE only one that actual works straight out of the box!!! Brilliant, well done."
Andrew Breward, Director of Technology caboodal.com
|
|