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 24 of 73
FILTER_VALIDATE_URL constant in PHP
The FILTER_VALIDATE_URL constant validates a URL and returns the validated URL on success or FALSE on failure. It's commonly used with the filter_var() function to check if a string contains a valid URL format. Syntax filter_var($url, FILTER_VALIDATE_URL, $flags) Parameters $url − The URL string to validate FILTER_VALIDATE_URL − The validation filter constant $flags − Optional flags to specify additional requirements Available Flags FILTER_FLAG_SCHEME_REQUIRED − URL must be RFC compliant with a scheme (http, https, etc.) FILTER_FLAG_HOST_REQUIRED − URL must include host name FILTER_FLAG_PATH_REQUIRED − URL must have a path ...
Read MoreFILTER_VALIDATE_FLOAT constant in PHP
The FILTER_VALIDATE_FLOAT constant validates whether a value is a valid float number. It returns the filtered data on success, or FALSE on failure. Syntax filter_var($value, FILTER_VALIDATE_FLOAT, $flags) Parameters $value − The value to validate as a float $flags (optional) − Additional flags like FILTER_FLAG_ALLOW_THOUSAND Return Value Returns the validated float value on success, or FALSE on failure. Example 1: Basic Float Validation float(291.9) Example 2: Testing Different Values Without flag: bool(false) With thousand separator flag: float(1234.56) ...
Read Morefilter_var() function in PHP
The filter_var() function is used to filter a variable with a specified filter. It provides a convenient way to validate and sanitize data in PHP applications. Syntax filter_var(variable, filter, options) Parameters variable − The value to filter filter − The filter ID that specifies the filter to apply options − Optional flags or options for the filter Return Value The filter_var() function returns the filtered data on success, or FALSE on failure. Example 1: Email Validation This example demonstrates validating an email address using FILTER_VALIDATE_EMAIL ? ...
Read Morefilter_input() function in PHP
The filter_input() function gets an external variable by name and optionally filters it using built-in PHP filters. It's commonly used to sanitize and validate user input from forms, URLs, cookies, and server variables. Syntax filter_input(type, var, filtername, options) Parameters type − Specifies the input type. Five constants are available: INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV. var − The name of the variable to filter. filtername − The ID of the filter to apply (e.g., FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_STRING). options − Optional flags or options for the filter. Return Value Returns the filtered ...
Read Morefilter_has_var() function in PHP
The filter_has_var() function is used to check whether a variable of a specified input type exists or not. This is particularly useful for validating user input from forms, URLs, and other sources. Syntax filter_has_var(type, var) Parameters type − Specifies the input type to check. Available options are: INPUT_GET − GET variables INPUT_POST − POST variables INPUT_COOKIE − COOKIE variables INPUT_SERVER − SERVER variables INPUT_ENV − Environment variables var − The name of the variable to check for existence Return Value Returns true if the variable exists, false ...
Read MoreHow to print results of script in MongoDB?
To print results of a script in MongoDB, use the printjson() method along with cursor iteration. This allows you to display query results in a formatted JSON structure, which is particularly useful when working with scripts or loops. Syntax var cursor = db.collection.find(); while (cursor.hasNext()) { printjson(cursor.next()); } Create Sample Data Let us first create a collection with documents ? db.printResultScriptDemo.insertMany([ {"StudentName": "John", "StudentAge": 21}, {"StudentName": "Carol", "StudentAge": 20}, {"StudentName": "David", "StudentAge": 19} ]); ...
Read MoreSpecify return format in MongoDB to return the values as an array?
To specify return format in MongoDB and return values as an array, use the aggregation pipeline with the $group stage and $addToSet operator to collect distinct values into an array. Syntax db.collection.aggregate([ { "$group": { "_id": null, "fieldName": { "$addToSet": "$fieldPath" } } }, { ...
Read MoreMongoDB query to select one field if the other is null and the first field if both are not null?
In MongoDB, to select one field when another is null and the first field when both are not null, use the $ifNull operator in an aggregation pipeline. This operator returns the first non-null value from the provided expressions. Syntax db.collection.aggregate([ { $project: { "fieldName": { "$ifNull": [ "$primaryField", "$fallbackField" ] } } } ]); Sample Data Let us ...
Read MoreLimit number of values in a field using MongoDB?
To limit the number of values in a field using MongoDB, use the $slice projection operator. This operator allows you to return only a specified number of elements from an array field. Syntax db.collection.find( {}, { "arrayField": { "$slice": numberOfElements } } ); Sample Data Let us first create a collection with documents ? db.numberOfValuesDemo.insertOne({ "Values": [100, 200, 300, 900, 1000, 98] }); { "acknowledged": true, "insertedId": ObjectId("5cefb736ef71edecf6a1f6ab") } ...
Read MoreProjection result as an array of selected items in MongoDB?
Use the distinct() method to project results as an array of selected items in MongoDB. This method finds distinct values for a specified field across a collection and returns them in an array format. Syntax db.collection.distinct("field", query) Sample Data Let us first create a collection with documents ? db.projectionListDemo.insertMany([ {"_id": "1", "Subject": ["MongoDB", "MySQL", "Java"]}, {"_id": "2", "Subject": ["MongoDB", "C", "C++"]}, {"_id": "3", "Subject": ["Java", "Python"]} ]); { "acknowledged": true, ...
Read More