Last Updated:

How to open a file with the .php extension?

First introduced in 1995, the PHP language today is one of the most popular in back-end web development, providing interaction with a large number of databases, HTTP requests, file types, types of information. It is distributed under an open license and continues to be updated, a vivid example of which is the release of the eighth specification in 2020.

The files in which the language interpreter will work are installed in the server settings. That is, nothing prevents you from entering your format there, which will be recognized when scripts work. By default, PHP works with:

  • .php
  • .phtml
  • .php2
  • .php4
  • .php5
  • .php6 (abandoned)
  • .php7
  • .php8
  • .html

The sixth version of the language was found to be too complex to create due to the limited environment in which it was created. The developers planned to introduce native support for UTF-32, which did not work out even in subsequent releases.

Edit a file

A notebook will be enough to edit PHP content, but it is not suitable for long-term work. The "easiest" alternative for a simple text editor and powerful programming environments is notepad++, which can be downloaded for free from the official website. Among its bright advantages are:

  • Support for dozens of syntaxes for highlighting, providing a quick understanding of code snippets and their types;
  • Specify line numbers, which makes it easier to debug.
  • Support for mass encodings, including UTF-8 with or without BOM;
  • advanced search and a lot of options for replacing any text.

To edit the PHP code, you need to change the content contained in the < and ">or <?php and?>. Less modern specifications also supported <% and %>, <scriptlanguage="php">and </script>. They tell the interpreter exactly where the PHP code is located, which is explained by its belonging to embedded programming languages – scripts can be inside various documents.

A prime example is php input into HTML, a commonly used usage scenario. Scripts in them are executed after setting the above tags at the beginning and end of the PHP code. On some web servers, it is not installed by default, then you will need to download it.

How to open File

If the goal is not to change the content, but to work with the script, you will need to place an existing file in the /public_html/ directory, and then start the web server and continue working. Just run a file with the .php format or similar will not work - the code simply will not be processed, but will be displayed "as is" or will cause problems in the code of the associated file.

You do not need to use compilers to get code that you will later need to save. It is enough to insert the script in the correct format and not process anything yourself.

Possible problems and their solution

Lack of server or necessary plugins

The most striking mistake, in which no PHP code works, is the launch of the file without using the server or the banal forgetfulness in installing its handler. The official website contains various instructions depending on the OS and server used. For example, to download PHP 5 on Debian with Apache installed, you will need to enter the following command in the terminal:

apt-get install php5-common libapache2-mod-php5 php5-cli

If the server was turned on, you should reboot it, sequentially specifying this:

/etc/init.d/apache2 stop
/etc/init.d/apache2 start

Incorrect encoding

Officially, PHP works with two encodings: UTF-8 and Latin1. The first is the most common and supports the Cyrillic alphabet, which is why it is recommended for use on almost all resources, which is what happens.

Change the encoding when you save the file. If it was additionally declared using HTML meta tags, you may also need to replace them.

How to open other files

Information on working with the following types of documents may also be useful:

  • .xml are created for structured data storage and are the basis for HTML. Open in notepad and support convenient parsing;
  • .ctb – data saved by the Cherrytree Linux application in SQLite format. Also launched by text editors;
  • .vsd – Infographic saved in OfficeVisio. For launch, both the official program from Microsoft and its free analogues (for example, LibreOffice) are suitable;
  • .xlsm– Excel tables that support macros. Open not only in Excel, but also in theAccess utility of the same developer;
  • .nrg – virtual disk images similar to .iso. Supported by a lot of applications, including DAEMONTools.