Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Ankith Reddy
Page 23 of 73
imagecolorset() function in PHP
The imagecolorset() function modifies the color of a specific palette index in palette-based images. This is particularly useful for creating flood-fill-like effects where you want to change all pixels of a particular color to a new color. Syntax imagecolorset(resource $image, int $index, int $red, int $green, int $blue [, int $alpha]) Parameters image − An image resource created by functions like imagecreate() index − The palette index to modify (0-255) red − Red component value (0-255) green − Green component value (0-255) blue − Blue component value (0-255) alpha − Transparency level (0-127, ...
Read Moreimagecolorclosestalpha() function in PHP
The imagecolorclosestalpha() function finds the index of the closest color in an image palette that matches the specified RGBA values. This function is particularly useful when working with palette-based images where you need to find the best color match including transparency. Syntax imagecolorclosestalpha(resource $image, int $red, int $green, int $blue, int $alpha) Parameters image − An image resource created by image creation functions like imagecreate() or imagecreatefrompng(). red − Red color component value (0-255). green − Green color component value (0-255). blue − Blue color component value (0-255). alpha − Alpha transparency value ...
Read Moreimagesx() function in PHP
The imagesx() function gets the width of an image resource in PHP. It returns the width of the image in pixels or FALSE on errors. Syntax imagesx(image) Parameters image − An image resource created by one of the image creation functions like imagecreatetruecolor(), imagecreatefromjpeg(), etc. Return Value The imagesx() function returns the width of the image in pixels as an integer, or FALSE on failure. Example The following example demonstrates how to get the width of a newly created image resource ? ...
Read Moreimagefill() function in PHP
The imagefill() function is used to perform a flood fill operation on an image, filling an area with a specified color starting from a given point. Syntax imagefill(img, x, y, color) Parameters img − An image resource created by functions like imagecreatetruecolor() or imagecreatefromjpeg() x − x-coordinate of the starting point for the fill operation ...
Read Moresleep() function in PHP
The sleep() function delays execution of the current script for a specified number of seconds. This is useful for creating pauses in script execution, rate limiting, or simulating delays. Syntax sleep(seconds) Parameters seconds − The number of seconds to delay the script (integer value). Return Value The sleep() function returns zero on success, or FALSE on failure. Example Here's a simple example demonstrating how sleep() pauses script execution − Start time: 02:54:50 After 2 seconds: 02:54:52 After 3 more seconds: 02:54:55 ...
Read Moreignore_user_abort() function in PHP
The ignore_user_abort() function sets whether a remote client can abort the running of a script. When enabled, the script continues executing even if the user closes their browser or navigates away from the page. Syntax ignore_user_abort(setting) Parameters setting − Optional boolean parameter. TRUE ignores user aborts (script continues running), FALSE allows user aborts to stop the script (default behavior). Return Value The ignore_user_abort() function returns the previous value of the user-abort setting as an integer (0 for false, 1 for true). Example 1: Getting Current Setting The following ...
Read Moredie() function in PHP
The die() function in PHP prints a message and immediately exits the current script. It's commonly used for error handling when critical operations fail. Syntax die(message) Parameters message − Optional. The message to display before terminating the script execution. Return Value The die() function does not return any value as it terminates the script execution. Example 1: Basic Usage Here's a simple example demonstrating die() with a custom message − Script started Script terminated! Example 2: Error Handling with File Operations The die() function is frequently used with file operations for error handling −
Read MoreFILTER_CALLBACK constant in PHP
The FILTER_CALLBACK constant calls a user−defined function to filter the value. This constant is used with filter_var() to apply custom filtering logic by passing a callback function. Syntax filter_var($value, FILTER_CALLBACK, array("options" => "callback_function")); Parameters The callback function is specified in the options array and receives the input value as a parameter. The function should return the filtered value. Example 1: Using Built−in Function This example converts a string to lowercase using PHP's built−in strtolower() function ? demo text! Example 2: Using Custom Function ...
Read MoreFILTER_SANITIZE_SPECIAL_CHARS constant in PHP
The FILTER_SANITIZE_SPECIAL_CHARS constant filter HTML-escapes special characters like , &, and quotes to prevent XSS attacks and ensure safe display in HTML. Syntax filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS, $flags) Flags FILTER_FLAG_STRIP_LOW − Strip characters with ASCII value below 32 FILTER_FLAG_STRIP_HIGH − Strip characters with ASCII value above 127 FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value above 127 Return Value Returns the sanitized string with special characters HTML-encoded, or FALSE on failure. Example Here's how to sanitize a string containing HTML special characters ?
Read MoreFILTER_SANITIZE_NUMBER_FLOAT constant in PHP
The FILTER_SANITIZE_NUMBER_FLOAT constant removes all illegal characters from a float number, keeping only digits, plus/minus signs, and optionally decimal points, thousand separators, or scientific notation based on the flags used. Syntax filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, $flags) Flags FILTER_FLAG_ALLOW_FRACTION − Allows decimal point (.) for fractions FILTER_FLAG_ALLOW_THOUSAND − Allows comma (, ) as thousand separator FILTER_FLAG_ALLOW_SCIENTIFIC − Allows e/E for scientific notation Return Value Returns the sanitized string with only valid float characters, or FALSE on failure. Example 1: Using ...
Read More