PHP Articles

Page 48 of 81

How to validate domain name in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In PHP, you can validate domain names using regular expressions with the preg_match() function. A valid domain name must follow specific rules: contain only alphanumeric characters and hyphens, have proper length limits, and follow DNS naming conventions. Example Here's a function to validate domain names ? The output of the above code is ? Domain: tutorialspoint.com - Valid Domain: sub.example.org - Valid Domain: test-site.net - Valid Domain: https://tutorialspoint.com - Invalid Domain: -invalid.com - Invalid Domain: toolongaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com - Invalid How It Works The validation function uses three regular expression ...

Read More

How to install Imagick/imagemagick PHP extension on Windows 10?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 331 Views

ImageMagick is a powerful image manipulation library, and the Imagick PHP extension provides an interface to use ImageMagick functions within PHP scripts. Installing it on Windows 10 requires downloading the appropriate binaries and configuring PHP properly. Prerequisites: Ensure you have PHP installed on Windows 10 with a web server like XAMPP, WAMP, or standalone Apache. Step 1: Download ImageMagick First, download the ImageMagick binary for Windows from the official website ? Visit https://imagemagick.org/script/download.php#windows Download the appropriate version matching your PHP architecture (x86 or x64) Install ImageMagick to the default directory (usually C:\Program Files\ImageMagick) ...

Read More

Getting size in memory of an object in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In PHP, you can determine the memory size of an object by using the memory_get_usage() function before and after object creation. This approach measures the difference in memory consumption to estimate the object's size. Basic Memory Measurement The most straightforward method involves capturing memory usage before and after object instantiation − Object memory size: 440 bytes Current memory usage: 2097720 bytes Memory Measurement with Real Memory For more accurate results, use the real_usage parameter to get actual memory allocated by the system − ...

Read More

PHP Call methods of objects in array using array_map?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In PHP, you can call methods of objects in an array using array_map() function. This is useful when you need to extract the same property or call the same method on multiple objects. Using Anonymous Functions (PHP 5.3+) The most straightforward approach uses anonymous functions − Array ( [0] => Laptop [1] => Mouse [2] => Keyboard ) Array ( [0] => 999.99 [1] => 25.5 [2] => ...

Read More

Is it possible to have a HTML SELECT/OPTION value as NULL using PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In HTML forms, SELECT/OPTION elements cannot have a truly NULL value when submitted via POST or GET. HTTP form data is always transmitted as strings, so the closest you can get to NULL is an empty string, which you can then convert to NULL in your PHP code. Understanding Form Data Transmission When a form is submitted, all values are sent as strings. Even if you set an option value to be empty, PHP receives it as an empty string (''). HTML Form Example ...

Read More

PHP equivalent of friend or internal

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 390 Views

PHP doesn't natively support friend classes like C++, but it can be simulated using magic methods __get() and __set() along with debug_backtrace(). This approach allows specific classes to access private properties, though it's considered a workaround rather than best practice. Simulating Friend Classes Here's how to implement friend-like behavior by checking the calling class in the backtrace ? This is private data Alternative Approach: Protected Properties A cleaner approach is using protected properties with inheritance ? Accessible to subclasses Key Points ...

Read More

How do I include a php.ini file in another php.ini file?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 516 Views

While PHP doesn't support directly including one php.ini file within another, you can achieve modular configuration through PHP's additional configuration directories feature. This approach allows you to split configurations across multiple .ini files. Using Configuration Scan Directory When compiling PHP from source, you can specify an additional directory for configuration files using the following compile option − --with-config-file-scan-dir=PATH The PATH parameter specifies the directory where PHP will scan for additional .ini files during startup. How It Works During PHP initialization, the engine will − First load the main php.ini file ...

Read More

Tracking Memory Usage in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

The memory_get_usage() function can be used to track the memory usage in PHP. The 'malloc' function is not used for every block required, instead a big chunk of system memory is allocated and the environment variable is changed and managed internally. The two different types of memory usages are − The memory required by the engine from OS (the real usage) The amount of memory that was actually used by the application (internal usage) The above mentioned memory usage can be tracked using memory_get_usage(). This function returns both real and actual memory used depending on ...

Read More

How to read a single file inside a zip archive with PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

To read a single file inside a zip archive, PHP provides a simple stream wrapper syntax that allows you to access files directly without extracting the entire archive. Syntax The basic syntax uses the zip:// stream wrapper − zip://path/to/archive.zip#filename_inside_zip Example Here's how to read a specific file from a zip archive using fopen() − Using file_get_contents() For simpler cases, you can use file_get_contents() directly − Key Points The # symbol separates the zip file path from the internal file path ...

Read More

PHP_CodeSniffer, PHPMD or PHP Depend

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 240 Views

PHP offers several powerful code analysis tools to help maintain code quality and enforce coding standards. Three essential tools − PHP_CodeSniffer (phpcs), PHPMD, and PHP Depend (pdepend) − each serve different purposes in code quality assessment. PHP_CodeSniffer (phpcs) PHP_CodeSniffer tokenizes PHP, JavaScript, and CSS files to detect violations against predefined coding standards. It ensures code consistency and helps prevent common semantic errors. Installation: Install via Composer: composer global require "squizlabs/php_codesniffer=*" Example Usage Here's how to check a PHP file against PSR−12 coding standard ? Command to run PHP_CodeSniffer ...

Read More
Showing 471–480 of 802 articles
« Prev 1 46 47 48 49 50 81 Next »
Advertisements