PHP: The big picture

來源:互聯網
上載者:User

標籤:style   http   io   color   os   ar   for   sp   div   

Before getting down to to the business of writing some real PHP, I want to take a few minutes to explain some basics. PHP needs to be processed by the web server before the page can be viewed in a browser. So, as a rule, you need to store all pages inside the server root. In most cases, this is a folder called htdocs. Although, it sometimes called www, www root, or public html. There are cases were PHP files can be stored outside the server root for security reasons. But that‘s something you can learn about at the later stage. The server relies on the file name extension to know whether to process a page as PHP.

Unless you‘re hosting a company or server administrator tells you otherwise, always use .php. You can mix pages with the .html file name extension in the same site. But it‘s a good idea to use .php for all files, even if they don‘t contain PHP code. By doing so, you can add PHP code later without needing to change the URL. PHP code should be enclosed in PHP tags. The opening tag consist of an opening angle bracket, question mark,and PHP. There‘s no space between any of the characters.

In some scripts, you‘ll find just the opening angle bracket followed by the question mark, without the PHP. This is a shortened version. It works on a lot of servers, but isn‘t guaranteed to work everywhere. So, I recommend that you should always use the full opening PHP tag. The closing tag is a question mark followed by a closing angle bracket. Now, in some cases you can omit the closing tag. But if there‘s any HTML or anything else on the web page other than PHP code, the closing tag must always be there. If in doubt, I recommend always using a closing tag. PHP can look daunting when you start out.

But you‘ll quickly recognize the common features. Variables act as place holders for unknown or changing values. Arrays hold multiple values. You use conditional statements to make decisions and loops to perform repetitive tasks. Functions and objects perform preset tasks. (JS亦是如此,這些語言有什麼共通點嗎?)When viewing PHP pages, it‘s important to remember that the PHP code must be processed by the web server. If you‘ve got into the habit of double-clicking HTML pages to view them locally, that won‘t work with PHP.

What will happen is that you‘ll either just see the raw code or you‘ll be prompted to download the file. So, it‘s important to remember that the server is running. It may sound obvious, but it‘s easy to forget, particularly in the early stages. And you should always view the page using a URL. So, in most cases, this will be HTTP:// local host, followed by wherever you‘ve put the file. Remember those basic points, and you‘ll soon discover that PHP isn‘t all that difficult to learn and is great fun to use.

PHP: The big picture

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.