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 George John
Page 27 of 79
imagedashedline() function in PHP
The imagedashedline() function in PHP draws a dashed line on an image resource. This function is part of the GD library and creates a line with alternating filled and empty segments between two specified points. Syntax imagedashedline($image, $x1, $y1, $x2, $y2, $color) Parameters image − An image resource created by functions like imagecreatetruecolor() x1 − Starting point x-coordinate y1 − Starting point y-coordinate x2 − Ending point x-coordinate y2 − Ending point y-coordinate color − Line color created with imagecolorallocate() Return Value Returns TRUE on success or FALSE on failure. ...
Read Moreusleep() function in PHP
The usleep() function delays execution of the current script for a specified number of microseconds. It is useful for creating pauses in script execution or controlling timing in loops. Syntax usleep(microseconds) Parameters microseconds − The number of microseconds to delay the script. One second equals 1, 000, 000 microseconds. Return Value The usleep() function returns void (nothing). Example Here's how to use usleep() to create delays in script execution ? Output The output shows timestamps with delays between them ? ...
Read Moretime_nanosleep() function in PHP
The time_nanosleep() function delays execution of the current script for a specified number of seconds and nanoseconds. This function provides more precise timing control than sleep() by allowing nanosecond-level precision. Syntax time_nanosleep(sec, nsec) Parameters sec − The number of seconds to delay the script. nsec − The number of nanoseconds to delay the script (0 to 999, 999, 999). Return Value The time_nanosleep() function returns true on success, or false on failure. If the delay was interrupted by a signal, it returns an associative array with information about the remaining ...
Read Morepack() function in PHP
The pack() function in PHP converts data into a binary string according to a specified format. This function is useful for creating binary data structures, network protocols, or file formats that require specific byte arrangements. Syntax pack(format, args) Parameters format − The format string specifying how to pack the data. Common format codes include: a − NUL-padded string A − SPACE-padded string ...
Read MoreFILTER_SANITIZE_URL constant in PHP
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 MoreFILTER_SANITIZE_NUMBER_INT constant in PHP
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 MoreFILTER_VALIDATE_REGEXP constant in PHP
The FILTER_VALIDATE_REGEXP constant validates a value against a Perl-compatible regular expression. It returns the validated value if the pattern matches, or FALSE on failure. Syntax filter_var($value, FILTER_VALIDATE_REGEXP, $options) Parameters $value − The string to validate $options − An array containing the "regexp" key with the pattern to match against Return Value Returns the validated string if it matches the pattern, or FALSE if validation fails. Example 1: Basic Pattern Matching This example validates an email domain pattern ? Matched String! ...
Read MoreFILTER_VALIDATE_EMAIL constant in PHP
The FILTER_VALIDATE_EMAIL constant is used with PHP's filter_var() function to validate email addresses. It checks if an email follows the standard email format and returns the email if valid, or false if invalid. Syntax filter_var($email, FILTER_VALIDATE_EMAIL) Return Value Returns the validated email address on success, or false on failure. Example Here's how to validate an email address using FILTER_VALIDATE_EMAIL − example@demo.com = valid email address Testing Invalid Emails Let's test with various invalid email formats − valid@example.com ...
Read MoreGet the size of a collection in MongoDB using conditions?
To get the size of a MongoDB collection using specific conditions, you can filter documents with a query and then calculate the total size of matching documents using Object.bsonSize() within a forEach() loop. Syntax var collectionSize = 0; db.collection.find({condition}).forEach(function(document) { var size = Object.bsonSize(document); collectionSize = collectionSize + size; }); print(collectionSize); Sample Data Let us create a collection with sample documents ? db.mongoDBCollectionSizeDemo.insertMany([ {"Name": "John", "Age": 23}, {"Name": "Chris", "Age": 24}, {"Name": ...
Read MoreCompare multiple properties in MongoDB?
To compare multiple properties in MongoDB, use the $where operator which allows JavaScript expressions to evaluate conditions between different fields or array elements within the same document. Syntax db.collection.find({ $where: "this.field1 > this.field2" }); Sample Data Let us create a collection with sample documents − db.comparingMultiplePropertiesDemo.insertOne({ "Values": [10, 70, 60] }); { "acknowledged": true, "insertedId": ObjectId("5cf228fcb64a577be5a2bc0a") } Display the document to verify insertion − db.comparingMultiplePropertiesDemo.find().pretty(); { ...
Read More