Articles on Trending Technologies

Technical articles with clear explanations and examples

highlight_file() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 367 Views

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 More

exit() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 1K+ Views

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 More

die() function in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 3K+ Views

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 More

define() function in PHP

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 1K+ Views

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 More

FILTER_CALLBACK constant in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 232 Views

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 More

FILTER_SANITIZE_URL constant in PHP

George John
George John
Updated on 15-Mar-2026 626 Views

The FILTER_SANITIZE_URL constant removes all illegal URL characters from a string, keeping only characters that are valid in URLs. This filter is useful for cleaning user input before using it in URL contexts. Allowed Characters The FILTER_SANITIZE_URL filter allows the following characters − $-_.+!*'(), {}|\^~[]`"> Original: https://example.com/search?q=hello world&type=web Sanitized: https://example.com/search?q=helloworld&type=web Key Points Spaces are removed from the input string Non-ASCII characters are stripped out Valid URL characters like ://, ?, &, and = are preserved This filter does not validate URLs, only sanitizes them Conclusion The ...

Read More

FILTER_SANITIZE_STRING constant in PHP

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 580 Views

The FILTER_SANITIZE_STRING constant removes HTML tags and encodes special characters from a string. This filter is useful for cleaning user input to prevent XSS attacks. Note: As of PHP 8.1.0, FILTER_SANITIZE_STRING is deprecated. Use htmlspecialchars() or custom validation instead. Syntax filter_var($value, FILTER_SANITIZE_STRING, $flags) Flags FILTER_FLAG_NO_ENCODE_QUOTES − Do not encode quotes FILTER_FLAG_STRIP_LOW − Removes characters with ASCII value less than 32 FILTER_FLAG_STRIP_HIGH − Removes characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_LOW − Encodes characters with ASCII value less than 32 FILTER_FLAG_ENCODE_HIGH − Encodes characters with ASCII value greater than 127 FILTER_FLAG_ENCODE_AMP − ...

Read More

FILTER_SANITIZE_SPECIAL_CHARS constant in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 947 Views

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 More

FILTER_SANITIZE_NUMBER_INT constant in PHP

George John
George John
Updated on 15-Mar-2026 787 Views

The FILTER_SANITIZE_NUMBER_INT constant removes all characters except digits, plus and minus signs from a string. It's commonly used to clean user input before processing numeric data. Syntax filter_var($value, FILTER_SANITIZE_NUMBER_INT) Parameters The filter_var() function with FILTER_SANITIZE_NUMBER_INT accepts − $value − The string to be sanitized FILTER_SANITIZE_NUMBER_INT − The filter constant that removes illegal characters Return Value Returns a string containing only digits (0-9), plus (+), and minus (-) signs. All other characters are removed. Example Here's how to sanitize a string containing mixed characters ?

Read More

FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 604 Views

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
Showing 22691–22700 of 61,299 articles
Advertisements