Browse and discover code scripts shared by the community. Find examples, learn from others, and share your own code snippets.
Check if an IPv4 Address is Inside a CIDR Range
Anonymous
Jun 14, 2026
Splits a CIDR into network and prefix, converts the test IP and network to integers via ip2long, builds a mask as -1 shifted left by 32 minus the prefix, and compares the masked values. Prefix zero matches everything; invalid input throws.
324 views
Relative Time Ago Formatter
Anonymous
Jun 14, 2026
Takes a DateTimeInterface and returns a string like 3 hours ago by diffing against now in seconds and matching the largest fitting unit from year down to second, with pluralization. Future and sub-second diffs are explicit cases.
130 views
Sparkline from Numbers Using Unicode Blocks
Anonymous
Jun 14, 2026
Maps a numeric series onto eight block characters by normalizing each value into the min..max range and scaling to an index 0..7. A flat series (zero range) renders the lowest block. Produces a compact inline chart you can print in a terminal or log line.
324 views
Weighted Random Selection
Anonymous
Jun 14, 2026
Picks a key with probability proportional to its integer weight. Sums the weights, draws an int in 1..total, then walks the cumulative weight until it meets or exceeds the draw and returns that key. Runs in one pass with no allocation beyond the inputs.
271 views
Bloom Filter in Pure PHP
Anonymous
Jun 14, 2026
Probabilistic set: hashes each item with crc32 plus a sha256-derived second hash, setting bits at h1 + i*h2 mod size for i hashes. mightContain returns false if any bit is unset (definitely absent), true otherwise (probably present). No false negatives.
219 views
Base62 Encoder for Short IDs
Anonymous
Jun 4, 2026
Encodes a non-negative integer to a compact base-62 string over 0-9a-zA-Z by repeated modulo and integer division, prepending digits. Decodes by scanning each char back through strpos on the alphabet. Good for short URL-safe slugs.
193 views
JSON Pointer (RFC 6901) Resolver
Anonymous
Jun 4, 2026
Walks a decoded JSON document by a slash-delimited pointer, unescaping ~1 to slash and ~0 to tilde in that order per the RFC, descending arrays by key and objects by property. Empty pointer returns the document, a missing segment throws.
238 views
Topological Sort with Kahn Algorithm
Anonymous
Jun 4, 2026
Builds an adjacency list and indegree map from a node-to-prerequisites graph, seeds a queue with zero-indegree nodes, then pops each, appends it, and decrements dependents. If fewer nodes come out than went in, a cycle exists.
274 views
LRU Cache in Pure PHP Using Ordered Arrays
Anonymous
Jun 4, 2026
Exploits PHP array insertion order: get() unsets and reappends the key so the most recently used sits at the tail, put() evicts via array_shift which drops the least recently used head when over capacity. Effectively O(1) amortized.
139 views
Human-Readable Byte Formatter and Parser
Anonymous
Jun 4, 2026
formatBytes derives the unit via floor(log(bytes,1024)), clamps to the unit table, and rounds value/1024^pow. parseBytes reverses it with a regex capturing the number and optional KB to PB suffix, then multiplies by 1024^index.
207 views
UUID v7 Generator (Time-Ordered) in Pure PHP
Anonymous
Jun 4, 2026
Builds a UUIDv7 by packing a 48-bit millisecond Unix timestamp into the first 12 hex chars, then 74 random bits from random_bytes, masking the version nibble to 7 and the variant bits to binary 10. Time-ordered so it indexes well as a primary key.
105 views
Finite State Machine (FSM) in Pure PHP
Anonymous
May 16, 2026
Stores current state and a transitions map keyed by [from_state][event]. trigger() looks up the next state, moves to it, appends to history, and fires the registered callback. on() accepts an array of source states for multi-origin transitions.
84 views
Showing 1-12 of 68 scripts

User-Shared PHP Scripts Repository

Welcome to our User-Shared PHP Scripts Repository! This is the perfect place for PHP developers to explore, share, and collaborate on various PHP scripts. Whether you’re looking for code snippets, libraries, or complete applications, you’ll find a wealth of resources contributed by fellow developers in our community.

Why Use User-Shared PHP Scripts?

  • Diverse Collection: Discover a wide range of PHP scripts covering various functionalities and projects, from simple utilities to complex frameworks.
  • Community-Driven: Benefit from scripts that are tried and tested by developers just like you, allowing for high-quality and practical solutions.
  • Learn and Collaborate: Enhance your coding skills by studying the shared scripts, and engage with other developers for feedback and support.

Features of Our Repository:

  • Easy Navigation: Browse through categories or use the search function to quickly find the script you need.
  • User Ratings and Comments: View community feedback on scripts to gauge their effectiveness and utility.
  • Share Your Own Scripts: Contribute to the community by sharing your own PHP scripts, helping others learn and grow.
  • Code Snippets and Examples: Access ready-to-use code snippets for common tasks to save time on your projects.

How to Use the Repository:

  • Browse or Search:

  • Use the navigation menu to explore different categories or utilize the search bar to find specific scripts.
  • View Script Details:

  • Click on a script to view its details, including a description, usage instructions, and user feedback.
  • Download and Use:

  • Download the script or copy the code to integrate it into your own projects.
  • Contribute Your Scripts:

  • Share your own PHP scripts with the community by submitting them through our easy-to-use submission form.

Why Contribute to the Repository?

  • Give Back to the Community: Share your knowledge and help other developers overcome challenges.
  • Gain Visibility: Showcase your work and establish your reputation within the PHP community.
  • Engage with Others: Collaborate with fellow developers and exchange ideas to improve your coding skills.

Conclusion

Explore our User-Shared PHP Scripts Repository today to find valuable resources and contribute to the community! Whether you’re looking to enhance your projects or share your expertise, this platform is here to support your PHP development journey. If you have any questions or need assistance, don’t hesitate to contact our support team.