PHP File Handling

PHP File handling is necessary for any web application. For particular tasks, you will frequently need to open and process a file. Uses of PHP File The following are some of the contexts in which we can need files in our web apps. Data is frequently saved in JSON files, and PHP code must read … Read more

PHP File Open

The PHP File Open method and modes will be covered in this chapter. PHP File Open – fopen() The fopen() function is a better way to open files. In comparison to readfile(), this function provides more options. Syntax: Parameters of fopen(): In PHP, the fopen() method takes four parameters. Parameter Data Type Description $file  Parameter … Read more

PHP File Read

The PHP File Read and close methods will be covered in this chapter. PHP Read File – fread() The fread() method reads data from a file that is currently open. The first parameter of fread() indicates the filename to read from, while the second defines the maximum number of bytes to read. The fread() function … Read more

PHP File Create/Write

The PHP File Create/Write methods will be covered in this chapter. PHP Create File – fopen() A file can also be created using the fopen() method. Perhaps puzzlingly, in PHP, a file is created using the same function that opens files. If a file with the same name already exists, fopen() will open it; otherwise, … Read more

PHP Form Required Fields

This chapter explains how to make input fields required and, if necessary, provide error messages. PHP Form Required Fields Let’s look at a PHP for fields, some of which cannot be left blank and must be filled out: Field Validation Rules Name Required+ It can only contain letters and whitespaces. E-mail Required. + Must contain a … Read more

PHP Form Validation

PHP Form Validation is the process of verifying the user’s input. In PHP, there are two forms of validation. The following is a list of them: Client-Side Validation: It is used for field validation and is performed on client machine web browsers. Server-Side Validation: After form submission, data is forwarded to a server, which performs validation checks. … Read more

PHP OOP – Encapsulation

Encapsulation allows us to hide properties and methods within a class such that they are not accessible by other classes. In PHP access modifiers are used for encapsulation, these modifiers are simply PHP keywords, to set the access permissions for class methods and variables. Some of the access modifiers can even be applied to the class … Read more

PHP OOP – Traits

In PHP multiple inheritance is not supported, which implies a child class can only have one parent class. Traits allow you to easily reuse methods across several classes that don’t have to be in the same hierarchy. Traits allow classes to reuse code horizontally, whereas inheritance allows reusing code vertically. Methods that can be utilized across … Read more

PHP OOP-Class Constants

Constants are bits of data saved in the computer’s memory that can not be modified once they have been assigned. Constants declared within classes are known as class constants. Declaring Class Constants A class constant is declared with the const keyword. Class constant must be declared inside class. Note: Class constants are case-sensitive. It is preferred that … Read more

PHP OOP – Inheritance

When a class descends from another class in Object-Oriented Programming, this is referred to as inheritance. The derived class is known as child/subclass. The class from which the child class is derived is known as the super/parent class. The parent class’s public and protected properties and methods are passed down to the child class. A … Read more