How to Hide Text in PHP File

How to Hide Text in PHP File
Page content

Good Coding Practices

Commenting code is a good practice for all programmers. Text hidden as comments doesn’t affect how the PHP file runs, but it does function as a great help to anyone else who has to read or edit the PHP file in the future. Every programming language has its own syntax for hiding text. Here you’ll learn how to hide text in a PHP file.

Fire Up the Text Editor

First, open the PHP file you wish to comment in a text editor. Ideally, you should be using a programming-oriented text editor such as TextMate (commercial) or TextWrangler (freeware). Notepad on Windows and TextEdit on OS X can be used in a pinch, but be careful to edit in plaintext mode so as not to introduce invisible rich text formatting characters to the PHP file’s code.

Decide Where to Put Hidden Text in Your PHP File

Now that the PHP file is open, choose where to hide text in it. Code is usually annotated at the very beginning with file information, such as the filename, the purpose of the code, version number, date, author information, and license information. Additionally, commenting the code itself is highly appreciated. You might want to add some hidden text explaining what the next section of code does, for example, or adding any other detail that is pertinent and would be helpful to readers who are unfamiliar with the code.

Experienced programmers agree that one sign of a good coder is copious commenting — it shows both thoughtfulness towards programmers who might have to make alterations to it in the future as well as demonstrating that the original programmer knew what they were doing and why.

Formatting Your Comments

There are two kinds of comments that can be used to hide text in a PHP file, and each has its own formatting method:

  • single-line comments
  • multiple-line comments

Single-line comments, suitable for short comments, are indicated by either a pound sign or two forward slashes before the comment. For example:

// Project: Super duper WordPress plugin

# Author: Jane Doe

Each of the above is a single-line comment and will remain hidden in your PHP file.

Multiple-line comments are longer annotations, and have formatting at the beginning and the end. At the beginning it’s a forward slash followed by an asterisk, and at the end it’s an asterisk followed by a slash. For example:

Picture 1

/*

Project: Super duper WordPress plugin

Author: Jane Doe

*/

We’ve taken the same single-line comments from above and turned them into one multiple-line comment. It’s personal preference which method you choose to use and when.

This concludes the short and, we hope, informative lesson on how to hide text in PHP file. In a PHP file, rather. Happy coding and remember: comment early and comment often.

Image Credits: Screenshots ©2010 Jacob Carson.