The Ultimate
Snippet Library.

Hundreds of production-ready scripts and coding solutions.
Brought to you by the experts at DigitalCodeLabs.

JAVASCRIPT

Track Previous State or Prop with `usePrevious`

Develop a `usePrevious` React hook to access the previous value of any state or prop, enabling comparisons and logic based on changes over time in your components.

View Snippet →
JAVASCRIPT

Respond to CSS Media Queries with `useMediaQuery`

Build a `useMediaQuery` React hook to programmatically detect if a CSS media query matches, allowing dynamic component rendering and styling based on screen size.

View Snippet →
JAVASCRIPT

Validate Email Address with Regex

Learn to validate email addresses using a robust regular expression in JavaScript to ensure correct format for user input.

View Snippet →
JAVASCRIPT

Validate URL Format with Regex

Implement a JavaScript function to validate URLs, ensuring they follow standard protocols (http/https) and domain structures.

View Snippet →
JAVASCRIPT

Validate Strong Password with Regex Criteria

Check password strength in JavaScript using regex to enforce requirements like uppercase, lowercase, numbers, special characters, and minimum length.

View Snippet →
JAVASCRIPT

Extract Hashtags from Text String

Discover how to efficiently extract all hashtags from a given text string using a regular expression in JavaScript, perfect for social media features.

View Snippet →
JAVASCRIPT

Remove HTML Tags from String Input

Sanitize user input by removing all HTML tags from a string using a regular expression, preventing potential cross-site scripting (XSS) vulnerabilities.

View Snippet →
PHP

Group Associative Array by Key

Efficiently group an array of associative arrays into a new array where items are grouped under keys derived from a specified common field.

View Snippet →
PHP

Flatten Multi-Dimensional Array

Convert a nested, multi-dimensional PHP array into a single-dimensional, flat array for easier iteration and processing.

View Snippet →
PHP

Sort Associative Array by Key Value

Sort an array of associative arrays based on the values of a specific key (e.g., sorting a list of products by price or name) in ascending or descending order.

View Snippet →
PHP

Recursively Merge Multiple Arrays

Combine multiple PHP arrays, including nested arrays, into a single array, prioritizing values from later arrays for common keys, useful for configuration.

View Snippet →
PHP

Filter Array and Re-index Numerically

Filter elements from a PHP array based on a callback function and then re-index the resulting array numerically, useful for creating clean lists.

View Snippet →