Server Side Programming Articles

Page 1049 of 2109

What is the use of ini_set() in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 6K+ Views

The ini_set() function in PHP allows you to modify PHP configuration settings at runtime for the current script. This is useful when you need to change settings that are normally defined in the php.ini file, but only for a specific script execution. Syntax ini_set(string $option, string|int|float|bool|null $value): string|false Parameters option The configuration option name to modify. Not all php.ini settings can be changed using ini_set() − only those with modes INI_USER or INI_ALL can be modified at runtime. value The new value for the configuration option. The value will be converted ...

Read More

What is the meaning of a Persistent Cookie in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 1K+ Views

A persistent cookie is a cookie that is stored permanently on the user's computer and remains available even after the browser is closed. Unlike session cookies which are temporary and stored only in browser memory, persistent cookies are saved to the hard disk and can be accessed across multiple browser sessions. Creating Persistent Cookies in PHP To create a persistent cookie in PHP, you must set an expiration time using the setcookie() function. The cookie will persist until the specified expiration date ? Reading Persistent Cookies You can retrieve persistent cookie values ...

Read More

What is .htaccess in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 8K+ Views

.htaccess is a configuration file for web servers running the Apache server software. When a .htaccess file is placed in a directory that is loaded via the Apache web server, the file is detected and executed by Apache. .htaccess files can be utilized to modify the setup of the Apache server software to enable additional functionality and features. We can use the .htaccess file for various configuration alterations in Apache web server software. Some common uses are listed below − ErrorDocuments Creating custom error pages allows us to show website visitors a friendly error message when a ...

Read More

Program to find how many times a character appears in a string in PHP

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 2K+ Views

In PHP, you can count how many times each character appears in a string by converting the string into an array and iterating through it. This technique is useful for text analysis and character frequency counting. Example Here's how to count character occurrences in a string ? Output w appears 1 times e appears 2 times l appears 2 times c appears 1 times o appears 4 times m appears 1 times t appears 4 times u appears 1 times r appears 1 times i appears 2 times a appears 1 ...

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 15-Mar-2026 549 Views

Yes, there are several advantages to using the magic function __construct() instead of the class's name for constructors in PHP − The magic function __construct() was introduced in PHP 5.0. One advantage of using __construct() over ClassName() as a constructor is if you change the name of the class, you don't need to update the constructor which supports DRY (don't repeat yourself) concept. If you have a child class you can call parent::__construct() to call the parent constructor in an easy way. Old-style constructors (using class names) are deprecated in PHP 7.0 and removed in PHP 8.0, making ...

Read More

How to Zip a directory in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 2K+ Views

We can use PHP's ZipArchive class to zip and unzip directories in PHP. As of PHP 5.3, this class is built-in. Windows users need to enable php_zip.dll in their php.ini file. Installation Note: Ensure the PHP Zip extension is enabled. On Windows, uncomment extension=zip in php.ini. On Linux, install with sudo apt-get install php-zip. Basic Directory Zipping Here's how to zip all files in a directory − Recursive Directory Zipping To zip directories with subdirectories, use this recursive function − Key Points ...

Read More

How To enable GZIP Compression in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 5K+ Views

GZIP compression is a simple, effective way to save bandwidth and speed up PHP applications by compressing content before sending it to the client. The mechanism works in three steps. How GZIP Compression Works Browser/Client Server 1. Request for file ...

Read More

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

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 6K+ Views

PHP 7 introduced the double question mark (??) operator, known as the Null Coalescing Operator. This operator returns its first operand if it exists and is not NULL; otherwise, it returns its second operand. The null coalescing operator evaluates from left to right and can be chained together for multiple fallback values. It's particularly useful for providing default values when working with potentially undefined variables. Syntax $result = $variable ?? $default_value; Basic Example Here's how the null coalescing operator works with an undefined variable − 9 ...

Read More

How to convert an array to SimpleXML in PHP?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 4K+ Views

In PHP, you can convert an array to SimpleXML using the array_walk_recursive() function combined with the SimpleXMLElement class. This approach transforms array keys into XML element names and array values into the element content. Note: If you encounter "Class 'SimpleXMLElement' not found" error, install the required packages: sudo apt-get install php-xml php-simplexml (Ubuntu/Debian) yum install php-xml (CentOS/RHEL) Basic Array to XML Conversion Here's how to convert a simple array structure to XML using array_walk_recursive() ? alex account michigan Advanced Method with Custom Function ...

Read More

How to validate an email address in PHP ?

Alok Prasad
Alok Prasad
Updated on 15-Mar-2026 9K+ Views

In PHP, validating email addresses is essential for ensuring data integrity and preventing invalid inputs. PHP provides several methods to validate email addresses, from built-in functions to custom regular expressions. Using filter_var() Function The most recommended approach is using PHP's built-in filter_var() function with the FILTER_VALIDATE_EMAIL filter − pattrick@tutorialspoint.com is a valid email address Using Regular Expression with preg_match() You can also create a custom validation function using regular expressions with preg_match() − Valid email address. Testing Invalid Email Examples ...

Read More
Showing 10481–10490 of 21,090 articles
Advertisements