Plug in PHP 100 POWER SOLUTIONS- P7 pps

5 349 0
Plug in PHP 100 POWER SOLUTIONS- P7 pps

Đang tải... (xem toàn văn)

Thông tin tài liệu

xxvi P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s xxvi P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s About PHP PHP was originally developed in 1994 by Rasmus Lerdorf to replace a set of Perl scripts he had been using to maintain his personal web site. The acronym originally stood for Personal Home Page, but when he released a version to the public the following year it was recursively retitled PHP: Hypertext Processor. Even in the early days, Lerdorf intended that PHP should be flexible and easily expandable, through rewrites of the language parser. This has remained a key ethos of the project to this day, with numerous extension libraries available through the PEAR (PHP Extension and Application Repository) add-on. Even without these extensions, PHP comes supplied with hundreds of ready-made functions—many more than in most other programming languages—making it a very rich development platform. No doubt this is a contributing factor towards its curr ent popularity, being installed on a third of all web servers, and behind only C++, C, and Java in usage for web development. There are many reasons to use PHP for web development. These include its incredible speed, which is even more remarkable given that it’s an interpreted language, its ease of use and interoperability with the MySQL database, and the fact that it’s almost always installed on any computer running the Apache web server. Prior to PHP, the most used scripting language was PERL, which was developed by Larry Wall in 1987. Originally intended as a general scripting language to automate report processing on Unix, it was adopted by many web developers too, and remains quite popular today. But, unlike PHP, PERL was never designed specifically for use on web sites, whereas PHP was written from the ground up with web development in mind, which may account for the fact that PHP is now more than twice as popular as PERL. Regarding learning and using the language, PHP is reasonably similar to other well- known languages such as C, Java, and Perl, whereas ASP uses Visual Basic (although ASP.net supports other languages). What’s more —ASP is built on the COM architecture, whereas PHP is not constrained this way and runs much faster. From a performance point of view, PHP is extremely fast and can support millions of accesses a day. According to Zend Technologies (www.zend.com), the writers of the main engine that PHP uses, PHP often outperforms the competition. Unlike Microsoft’s ASP (Active Server Pages), PHP is available on multiple platforms and, because it is free (open source software), it can be implemented at little cost other than that of the hardware it runs on. Interestingly a quick check at Google for the searches “filetype:php” and “filetype:asp” returns 7.4 billion PHP pages and 1.8 billion ASP pages on the web. That’s a ratio of over four to one in favor of PHP. You may be surprised at some of the sites that use PHP as their backbone because you probably know many of them. Here’s a list of just five top web sites that use PHP for some or all of their site’s programming: • Yahoo! A popular search engine (see Figure 1) • Facebook A social networking site • Wikipedia A collaborative encyclopedia • Photobucket A photo sharing service • Digg A technology news bookmarking site Actually, Yahoo! shouldn’t be too much of a surprise because Rasmus Lerdorf has worked at the company as a Distinguished Engineer since 2002. So why is PHP so popular? There are three main reasons. First, PHP integrates seamlessly with HTML. Even if you know next to no programming, it’s very easy to rename your .html files to .php and they will automatically become PHP programs, albeit ones that display themselves as an HTML page. But then, whenever you need a little dynamic functionality, you can drop in a quick line of PHP code, like the following snippet, which will display the day of the week: <?php echo date("l"); ?> Second, it’s easy to learn. With a few simple PHP functions under your belt, almost without knowing it, you’re already a PHP programmer. Add in for loops and a couple of other constructs and you can very quickly start making your own dynamic web sites. Third, there’s excellent support from the PHP programming community and books such as this. Just type “help PHP” into Google and you’ll be presented with a staggering 125 million search results. I n t r o d u c t i o n xxvii FIGURE 1 Yahoo! is possibly the best-known web company that uses PHP extensively. xxviii P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s xxviii P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s What This Book Provides Having access to all of PHP’s functions isn’t very useful when you need to quickly put together a project to a tight deadline, because the functions typically provide very specific functionality. Even PEAR plug-ins are not always the complete solution either, since they usually take time to learn and still must be wrapped in PHP code of your own devising. That’s where this book comes into its own, because it provides 100 ready-to-go plug-ins you can simply drop into your programs and use, normally with a simple, single call. Of course, because all projects are different I only provide the bare bones needed and leave layout and styling to the absolute minimum. This leaves you free to grab a plug-in, insert it into your own program, and then tailor it to your exact requirements. The types of plug-ins supplied offer quick and simple solutions to a very wide range of problems including processing text in a variety of ways, uploading and manipulating images, server content management, form handling, user input validation, chat and messaging, user authentication and security, integration with third-party web sites, and much more besides. With them you can avoid having to reinvent the wheel each time you need a new feature, because the chances are that the module you need (or one very similar) can be found in this book as a plug-in. And even if it isn’t, because each and every plug-in is broken down into component parts and explained in detail, you should find you can cherry-pick code segments from different plug-ins to build your own. About the Plug-ins All of this book’s plug-ins are ready-to-run and can be either typed in if you don’t have Internet access, or you can download them from www.pluginphp.com (see Figure 2) where they are stored as both individual plug-ins and also grouped into larger collections by theme. For example, all the authentication and security plug-ins can be found in the file security.php. When you visit the web site, you can navigate through the plug-ins chapter by chapter, and also view the PHP program code highlighted in color for clarity. From there, you can copy, paste, or download individual plug-ins, groups, or the whole collection directly to your computer. What Is and Isn’t Included Although the first aim of this book is to provide newcomers to PHP with a comprehensive resource of functions and routines to draw on, it has a secondary goal, which is to help you move up to the next level and to create your own programming toolkit. Therefore every plug-in is thoroughly documented and explained in detail, and advice is given on ways to improve and extend them, as well as how to adapt them to your own requirements. To aid with this, I have attempted to stick with a basic subset of PHP functions so you can familiarize yourself with them as you work through the book. Except for cases where it is unavoidable, I have also steered clear of advanced techniques such as object-oriented programming (OOP), so most of the plug-ins work (and can be explained) in a procedural manner. Of course, OOP is powerful and, if you don’t already use it, you really should learn it because you’ll find your productivity rate increases substantially. And while this book isn’t a programming manual or a teaching guide, I do hope that by reading through the plug-in explanations, rather than just including them in your projects, you’ll pick up a number of tips and tricks that many programmers take years to discover, and by osmosis you will learn more about the PHP programming language. Plug-in License You are free to use any of the plug-ins in this book in your own projects, and may modify them as necessary, without attributing this book—although if you do so, it will always be appreciated. However, you may not sell, give away, or otherwise distribute the plug-ins themselves in any manner, whether printed or in electronic format, without the written permission of the publisher. Companion Web Site A companion web site (at www.pluginphp.com) accompanies this book, where all 100 plug-ins are available to download, along with example code for you to experiment with. The site also includes useful extras such as an 80,000-word dictionary and a geo-location IP data file. I n t r o d u c t i o n xxix FIGURE 2 All the plug-ins from this book can be downloaded from www.pluginphp.com. xxx P l u g - i n P H P : 1 0 0 P o w e r S o l u t i o n s The web site is best used in conjunction with this book. As you read a chapter, call it up on the web site, too, and you can list each plug-in on screen with color-highlighted syntax. This makes it very easy to see the structure of each program. When you wish to, you can click a link to copy and paste a particular plug-in right into your own programs. Or, if you prefer, you can download all of the plug-ins to your computer from where you can pick the one(s) to upload to your own web site. To help you with accessing them, the plug-ins are all stored in groups of ten per file, each file having a certain theme, such as image manipulation or text processing, and so on. You can then copy and paste from these files, or use a PHP include command to incorporate them in your own programs. There is also a blog where you can keep up to date with the latest developments, as well as a forum where you can share your experiences and ask for assistance if you need it. . of problems including processing text in a variety of ways, uploading and manipulating images, server content management, form handling, user input validation, chat and messaging, user authentication. similar) can be found in this book as a plug- in. And even if it isn’t, because each and every plug- in is broken down into component parts and explained in detail, you should find you can cherry-pick. different plug- ins to build your own. About the Plug- ins All of this book’s plug- ins are ready-to-run and can be either typed in if you don’t have Internet access, or you can download them from www.pluginphp.com

Ngày đăng: 07/07/2014, 08:20

Từ khóa liên quan

Mục lục

  • Contents

  • Acknowledgments

  • Introduction

  • 1 Building a Development Server

    • Windows XP, Windows Vista, and Windows 7

      • Reinstalling Zend Server CE

      • Upgrading Zend Server CE

      • Windows Security Alerts

      • After Installation

      • Uninstalling

      • Document Root

      • Ubuntu and Debian Linux

        • Uninstalling

        • After Installation

        • Document Root

        • Fedora, RHEL, and CentOS Linux

          • Installing MySQL

          • Uninstalling

          • Document Root

          • Other Versions of Linux

            • Installing MySQL

            • Uninstalling

            • Document Root

            • Mac OS X 10.4 Plus on Intel Chips

              • Document Root

              • Uninstalling

Tài liệu cùng người dùng

Tài liệu liên quan