Alok Prasad has Published 38 Articles

Is there any advantage to using __construct() instead of the class's name for a constructor in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:51:56

447 Views

Yes, there are several advantages to using the magic function __construct() instead of the class's name. Those are listed below −The magic function __construct is introduced in PHP 5.4. One advantage of using __construct() over ClassName() as a constructor is if you change the name of the class, you don't ... Read More

How to Zip a directory in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:47:35

2K+ Views

We can use PHP ZipArchive class in order to zipping and unzipping the folder in PHP. As of PHP 5.3, this class is inbuilt. For using in windows users need to enable php_zip.dll inside of php.ini.Example

How To enable GZIP Compression in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:41:43

5K+ Views

GZIP Compression is a simple, effective way to save bandwidth and speed up PHP application. The mechanism runs behind the GZIP compression is described below −Step1The browser/client request for a file to the server.Step2The server sends a .zip file to the browser (index.html.zip) rather than plain old index.html in response, ... Read More

What is singleton design concept in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:38:58

4K+ Views

Singleton Pattern ensures that a class has only one instance and provides a global point to access it. It ensures that only one object is available all across the application in a controlled state. Singleton pattern provides a way to access its only object which can be accessed directly without ... Read More

What does double question mark (??) operator mean in PHP ?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:37:56

5K+ Views

PHP 7 has added a new operator double question mark (??) operator. In PHP 7, the double question mark(??) operator known as Null Coalescing Operator.It returns its first operand if it exists and is not NULL; otherwise, it returns its second operand. It evaluates from left to right. Null Coalescing ... Read More

How to remove non-alphanumeric characters in PHP stirng?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:24:11

3K+ Views

We can remove non-alphanumeric characters from the string with preg_replace() function in PHP. The preg_replace() function is an inbuilt function in PHP which is used to perform a regular expression for search and replace the content.syntaxpreg_replace(pattern, replacement, subject, limit, count )Let's discuss the parameters of the function underneath.patternThis parameter contains ... Read More

What is PHP Output Buffering?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:23:08

3K+ Views

Output Buffering is a method to tell the PHP engine to hold the output data before sending it to the browser. As we know PHP sent the output data to the browser in pieces, but if we utilize the output buffering mechanism, the output data is stored in a variable ... Read More

How to validate an email address in PHP ?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:21:32

9K+ Views

In this article, we will learn to validate an email with PHP regular expression. We will learn different methods to validate email address in PHP.Method1The function preg_match() checks the input matching with patterns using regular expressions.Example Live DemoOutputValid email address.In the above example PHP preg_match() function has been used to search ... Read More

How to convert an array to SimpleXML in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:20:10

4K+ Views

We can solved the above problem using array_walk_recursive() function.array_walk_recursive()   is an inbuilt PHP function. This function converts array to XML document where keys of the array are converted into values and values of the array are converted into the element of XML.Let' demonstrate with a simple example.ExampleOutput ... Read More

How to call parent constructor in child class in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:06:57

4K+ Views

We will face two cases while calling the parent constructor method in child class.Case1We can't run directly the parent class constructor in child class if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.Example Live DemoOutput: I ... Read More

Advertisements