What is PHP and what do I need?
I explain what you need to start working with PHP. Before doing so, I think it‘ll be useful to explain what PHP is and how it works. PHP stands for PHP: Hypertext Preprocessor. It‘s a rather ugly name for a very powerful scripting language that‘s relatively easy to learn. You can use PHP in your websites for a wide range of tasks, such as processing online forms, uploading files.
When working with images, you can automatically generate thumbnails or watermarks. PHP can also read and write files directly on your server. And one of its most important uses is communicating with the database. Most of the time, PHP is used with the open source MySQL database. But it also works with all leading databases. There‘s much more that you can do with PHP. But in this introductory workshop, I‘m going to explain the basic structure of the language, and then show you how to process a contact form and email its contents.
Once you understand the basics of PHP, you‘ll find it a lot easier to expand your knowledge and then apply them to a wide range of projects. Let‘s take a quick look at how PHP works. When someone visits a website, the browser sends a request to the web server. With a static webpage that just consists of HTML, CSS images, and maybe JavaScript, the server simply responds by sending all the necessary files.
However, if you use PHP in your webpages, the service sends the page to the PHP engine for processing before sending the response to the browser. And if a database is involved, the PHP engine is responsible for sending the request to database and processing the results. All this usually takes only a fraction of a second, so there‘s no noticeable delay. PHP was designed as an embedded language. What that means is that PHP code is often mixed or embedded in HTML markup. This is the HTML markup for a basic feedback form. And here, on lines 28 and 30, are PHP commands that wrap around this paragraph. Here‘s the same web form in a browser.
And as you can see, that paragraph isn‘t displayed. But if I submit the form without filling in any of the fields, the paragraph is displayed along with other error messages. What‘s happened is that the PHP script has processed the form, discovered errors, and displayed all the messages(we can also use JS to do that ). But take a look at the page‘s source code. There‘s no PHP in sight. It‘s just HTML. That‘s because PHP is a server-side technology.
The PHP code remains on the server and after it‘s been processed or parsed, it outputs text and HTML. So, what do you need to get started with PHP? First of all, you need a PHP-enabled web server. Of course, your remote server, the one that hosts your website, needs to support PHP. And you could use it for testing and development. But it‘s not a good idea. It‘s much better to set up a local testing environment. In the early days, you‘re likely to make mistakes.
So, working locally is both safer and quicker. You don‘t need to keep uploading your files every time you make a change. Even when you become more experienced, you‘ll appreciate being able to develop offline in your local testing environment. You also need a suitable script editor to write your PHP code. PHP is written in plain text like HTML and CSS. So, you don‘t need anything special, but I‘ll offer some suggestions. For your local testing environment, I recommend using XAMPP for Windows or MAMP on Mac OS X. Both provide you with all the necessary components.
The Apache web server, PHP, the MySQL database system, and a web based front end for MySQL called phpMyAdmin. By the way, don‘t be confused by the fact that Apache is called a web server. It‘s a piece of software that you install on your local computer. You don‘t need a separate server computer. We won‘t be using MySQL or phpMyAdmin in this workshop. But they‘re useful to have installed for when you‘re ready to move onto the next stage with PHP development. Separate videos show how to set up XAMPP and MAMP. However, you don‘t need to install them if you already have a suitable PHP setup, such as, WAMP, Easy PHP, or PHP running on IIS. Just make sure that you‘re running PHP 5.2 or later. Although, PHP is a plain text, I strongly recommend that you use a script editor with the following features: a PHP syntax checker to make it easy to spot mistakes in your code, syntax coloring to highlight the different parts of the language, this also helps identify mistakes, code hints to remind you of how to use built in and custom functions, line numbering, and a feature to identify matching opening and closing braces.
Here are some suggestions for script editors that have all those features. Among the free offerings, PHP development tools, PDT, and Komodo Edit, are good. Zend Studio and PhpED aren‘t free, but they‘re dedicated to working with PHP and are worth investigating if you plan to do a lot of PHP work. Dreamweaver isn‘t a dedicated PHP editor, but Dreamweaver CS5 and later has excellent support for PHP. And that‘s what I‘ll be using throughout this workshop. But it doesn‘t matter which editors you use.
The code you‘ll learn about in these videos is the same. What‘s more, it‘s platform-neutral. The same code works on Windows, Mac OSX, and Linux.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。