Hướng dẫn what is a php document? - một tài liệu php là gì?

In this quick post, we’re going to discuss the ins and outs of a PHP file. If you're new to PHP programming, this article should help you to understand various aspects of a PHP file.

PHP is a server-side scripting language which is mostly used to build web-based applications. These may range from a very simple blog website to a full-fledged eCommerce website for selling products online. In fact, PHP is one of the most popular server-side scripting languages, with a very healthy market share.

So when you start learning PHP programming, the first thing you should do is make yourself familiar with .php files.

What Is a PHP File?

When it comes to learning the PHP scripting language, you'll be creating and coding files with the .php extension. So what exactly is a PHP file?

Generally speaking, a PHP file is a plain-text file which contains code written in the PHP programming language. Since PHP is a server-side [back-end] scripting language, the code written in the PHP file is executed on the server. The PHP engine on the web server converts all the code written in PHP to HTML, so the resulting web page contains only HTML code when it’s sent to the client side for rendering in the user browser.

In fact, a PHP file may contain plain text, HTML tags, or code as per the PHP syntax. When you access any PHP-based web page, the request is sent to the server, where the PHP code is interpreted and executed by the PHP engine. The PHP code is converted to HTML, and it’s merged with the other plain text and HTML in the file. Finally, the completed HTML is sent to the client after the page executes.

If you view the source of any PHP file in a browser, you’ll never see the original PHP code in it, since it’s already executed and converted to HTML by the server.

That's an overview of how a PHP file works. In the next section, we’ll see an example of what a PHP file looks like.

Structure of a PHP File

In this section, we’ll quickly go through the structure of a PHP file. Let’s have a look at an example PHP file:

In the above example, the code which is wrapped by tags is a piece of PHP code. And as we discussed in the previous section, a PHP file may contain code other than PHP, and it may be plain text or HTML tags. The code which is wrapped by tags is executed on the server side. In the case of the above example, the output looks like this after PHP code execution:

Hello World

In fact, the structure of a PHP file may look like:


other HTML tags
plain text

more HTML

So as you can see, a PHP file can mix code, HTML, and plain text.

The short_open_tag Tag

In the previous section, we saw that the PHP code is wrapped by tags in a PHP file. However, the php.ini configuration file provides a directive named short_open_tag, which allows you to use a short form of PHP’s open tag.

If you enable the short_open_tag directive, you can wrap your PHP code between

Hello World
2 and ?> instead of , and it’ll work perfectly. You can set this and other directives in the php.ini configuration file. I explain how to find and use this in another post.

There is one catch—if you use the short open tag, you need to be careful when combining PHP code with XML code, since the syntax of the opening XML tag

Hello World
6 may create issues, and that XML code would be detected as PHP.

In fact, it’s considered a best practice to avoid using a short form of PHP’s open tag.

And with that, we’ve reached the end of this quick tutorial. I hope this post has helped you to understand the basics of a PHP file. You can learn more about PHP programming in the courses and tutorials here on Envato Tuts+!

Or if you want to learn how to use PHP for WordPress, check out our free course.

The Best PHP Scripts on CodeCanyon

CodeCanyon is a marketplace for plugins and scripts. You can explore thousands of the best and most useful PHP scripts ever created on CodeCanyon. With a low-cost one-time payment, you can purchase these high-quality WordPress themes and improve your website experience for you and your visitors.

Here are a few of the best-selling and up-and-coming PHP scripts available on CodeCanyon for 2020.

Bạn có thấy bài đăng này hữu ích?

Kỹ sư phần mềm, FSPL, Ấn Độ

Tôi là một kỹ sư phần mềm chuyên nghiệp, và tôi đã thực hiện kỹ thuật khoa học máy tính. Đã khoảng 14 năm tôi đã làm việc trong lĩnh vực phát triển trang web và công nghệ nguồn mở. Chủ yếu, tôi làm việc trên các dự án và khung dựa trên PHP và MySQL. Trong số đó, tôi đã làm việc trên các khung web như Codeignitor, Symfony và Laravel. Ngoài ra, tôi cũng có cơ hội làm việc trên các hệ thống CMS khác nhau như Joomla, Drupal và WordPress và các hệ thống thương mại điện tử như Magento, Opencart, WooC Commerce và Drupal Commerce. Tôi cũng muốn tham dự các hội nghị công nghệ cộng đồng, và là một phần của điều đó, tôi đã tham dự Hội nghị Thế giới Joomla 2016 được tổ chức tại Bangalore [Ấn Độ] và 2018 Drupalcon được tổ chức tại Mumbai [Ấn Độ]. Ngoài ra, tôi thích đi du lịch, khám phá những địa điểm mới và nghe nhạc!

Các tệp PHP là gì?

Hàm is_file [] trong PHP là hàm sẵn được sử dụng để kiểm tra xem tệp được chỉ định có phải là tệp thông thường hay không.Tên của tệp được gửi dưới dạng tham số cho hàm is_file [] và nó trả về true nếu tệp là một tệp thông thường khác, nó trả về sai.an inbuilt function which is used to check whether the specified file is a regular file or not. The name of the file is sent as a parameter to the is_file[] function and it returns True if the file is a regular file else it returns False.

Làm cách nào để viết một tài liệu PHP?

PHP ghi vào tệp - fwrite [] hàm fwrite [] được sử dụng để ghi vào tệp.Tham số đầu tiên của fwrite [] chứa tên của tệp để ghi vào và tham số thứ hai là chuỗi được viết.fwrite[] The fwrite[] function is used to write to a file. The first parameter of fwrite[] contains the name of the file to write to and the second parameter is the string to be written.

Làm cách nào để mở tệp PHP?

Tệp PHP được đặt bên trong thư mục HT HTDOCS.Nếu bạn muốn chạy nó, hãy mở bất kỳ trình duyệt web nào và nhập vào localhost/demo.php và nhấn enter.Chương trình của bạn sẽ chạy.open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

PHP và ví dụ là gì?

PHP là ngôn ngữ kịch bản phía máy chủ được tạo ra vào năm 1995 bởi Rasmus Lerdorf.PHP là một ngôn ngữ kịch bản đa năng nguồn mở được sử dụng rộng rãi, đặc biệt phù hợp để phát triển web và có thể được nhúng vào HTML.a server-side scripting language created in 1995 by Rasmus Lerdorf. PHP is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Bài Viết Liên Quan

Chủ Đề