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 Chandu yadav
Page 25 of 81
imagecolorallocate() function in PHP
The imagecolorallocate() function in PHP allocates a color for an image using RGB values. This function is essential for creating colored graphics and backgrounds in image manipulation. Syntax int imagecolorallocate($image, $red, $green, $blue) Parameters $image: Image resource created with imagecreatetruecolor() or imagecreate() $red: Red color component (0-255) $green: Green color component (0-255) $blue: Blue color component (0-255) Return Value Returns a color identifier on success, or FALSE on failure. The color identifier can be used with other image functions. Example Here's how to create an image with a ...
Read Moreimagecreate() function in PHP
The imagecreate() function is used to create a new palette−based image resource in PHP. While functional, it's recommended to use imagecreatetruecolor() instead for better image quality, as it creates true color images that support millions of colors rather than the 256−color palette limitation of imagecreate(). Syntax imagecreate($width, $height) Parameters Parameter Type Description $width int The width of the image in pixels $height int The height of the image in pixels Return Value Returns an image resource identifier on success, or FALSE on failure. ...
Read Moregetimagesize() function in PHP
The getimagesize() function in PHP is used to retrieve the dimensions and other information about an image file. It can work with both local files and remote URLs, returning an array containing width, height, image type, and additional metadata. Syntax getimagesize(file_name, img_info) Parameters file_name − The path to the image file (local or remote URL) img_info (optional) − An array to store extended information from the image file. Currently supports only JFIF files Return Value The function returns an indexed array with the following elements ? [0] − ...
Read Morephp_strip_whitespace() function in PHP
The php_strip_whitespace() function returns PHP source code with stripped comments and whitespace, making it useful for code optimization and analysis. Syntax php_strip_whitespace(file_path) Parameters file_path − The path to the PHP file to be processed. Return Value The php_strip_whitespace() function returns the stripped source code as a string on success, or FALSE on failure. Example Let's create a sample PHP file and then use php_strip_whitespace() to process it ? Now, let's strip the whitespace and comments ? ...
Read Morehighlight_file() function in PHP
The highlight_file() function outputs a file with the PHP syntax highlighted using colors. It's useful for displaying PHP source code in a readable, formatted way on web pages. Syntax highlight_file(file, return) Parameters file − The file name to display. Can be a relative or absolute path to the PHP file. return − Optional boolean parameter. If set to true, the function returns the highlighted code as a string instead of printing it directly. Default is false. Return Value Returns true on success or false on failure when the return parameter ...
Read Moreexit() function in PHP
The exit() function in PHP prints a message and terminates the current script execution immediately. It can accept an optional message parameter to display before exiting. Syntax exit(msg) Parameters msg − Optional. The message to display before exiting the script. Can be a string or an integer exit status code. Return Value The exit() function does not return any value as it terminates script execution. Example 1: Basic Usage Here's a simple example showing how exit() works − Before exit Script terminated! Example 2: File Operation with Error Handling The exit() function is commonly used for error handling when operations fail −
Read Moredefine() function in PHP
The define() function defines a constant in PHP. Constants are global variables whose values cannot be changed during script execution. Syntax define(const_name, value, case_insensitive) Parameters const_name − The name of the constant (string). value − The value of the constant (scalar value). case_insensitive − Optional. Whether the constant name should be case-insensitive (default: false). Return Value The define() function returns true on success or false on failure. Examples Basic Example The following example defines a constant and accesses it directly ? ...
Read MoreFILTER_SANITIZE_ENCODED constant in PHP
The FILTER_SANITIZE_ENCODED constant in PHP is used with the filter_var() function to URL-encode special characters in a string. This is particularly useful for sanitizing URLs and ensuring they contain only valid characters. Syntax filter_var($value, FILTER_SANITIZE_ENCODED, $flags) Flags and Options FILTER_FLAG_STRIP_LOW − Remove characters with ASCII value less than 32 FILTER_FLAG_STRIP_HIGH − Remove characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_LOW − Encode characters with ASCII value less than 32 FILTER_FLAG_ENCODE_HIGH − Encode characters with ASCII value greater ...
Read MoreFILTER_VALIDATE_IP constant in PHP
The FILTER_VALIDATE_IP constant validates an IP address using PHP's filter_var() function. It checks if a given string is a valid IPv4 or IPv6 address format. Syntax filter_var($value, FILTER_VALIDATE_IP, $flags) Parameters $value − The IP address string to validate FILTER_VALIDATE_IP − The validation filter constant $flags − Optional flags to specify validation criteria Flags FILTER_FLAG_IPV4 − The value must be a valid IPv4 address FILTER_FLAG_IPV6 − The value must be a valid IPv6 address FILTER_FLAG_NO_PRIV_RANGE − The value must not be within a private range FILTER_FLAG_NO_RES_RANGE − The value must ...
Read MoreFILTER_VALIDATE_BOOLEAN constant in PHP
The FILTER_VALIDATE_BOOLEAN constant validates a value as a boolean option. It's useful when you need to convert string representations of boolean values into actual PHP boolean types. Return Value The FILTER_VALIDATE_BOOLEAN constant returns: TRUE for "1", "true", "on" and "yes" FALSE for "0", "false", "off" and "no" NULL for any other value Syntax filter_var($value, FILTER_VALIDATE_BOOLEAN, $flags) Example 1: Valid TRUE Values This example shows values that return TRUE − bool(true) bool(true) bool(true) Example 2: Valid FALSE Values This example demonstrates ...
Read More