Alok Prasad has Published 52 Articles

What is dependency injection in PHP?

Alok Prasad

Alok Prasad

Updated on 29-Jun-2020 11:54:40

9K+ Views

Dependency injection is a procedure where one object supplies the dependencies of another object. Dependency Injection is a software design approach that allows avoiding hard-coding dependencies and makes it possible to change the dependencies both at runtime and compile time.There are numerous approaches to inject objects, here are couple generally ... Read More

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

317 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

What are the methods for sanitizing user inputs with PHP?

Alok Prasad

Alok Prasad

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

281 Views

Sanitizing of inputs is an interesting concept in PHP. Sanitizing means escaping the unauthorized characters in the input. Let's learn some best practices to process the inputs in a safe and secure way.Use of real_escape_string() funnction in mysqli statements.Examplewe can use htmlentities() and html_entity_decode() while insert data in database and ... 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

4K+ 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

3K+ 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

4K+ 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

2K+ 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

8K+ 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

Advertisements