Download the PHP package klkvsk/clearurls without Composer
On this page you can find all versions of the php package klkvsk/clearurls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package clearurls
ClearUrls PHP
High-performance PHP library for removing tracking parameters from URLs using the ClearURLs ruleset.
Features
- ๐ Fast - Optimized for bulk URL cleaning with pre-compiled regex patterns
- ๐ฏ Zero Dependencies - Pure PHP 8.3+ standard library only
- ๐ Auto-updating Rules - Fetches latest rules from ClearURLs project
- ๐งช Well Tested - Comprehensive test suite with performance benchmarks
- ๐ช Production Ready - Battle-tested rules from the ClearURLs community
- ๐ฆ Easy Integration - Simple, one-function API
Installation
Requirements
- PHP 8.3 or higher
- Composer
Using Composer
The package includes pre-compiled rules (src/Rules.php), so it's ready to use immediately after installation.
Quick Start
Usage Examples
Basic URL Cleaning
Handling Redirections
Referral Marketing
By default, referral marketing parameters (like Amazon affiliate tags) are removed. To keep them:
Checking Result Status
Batch Processing
Custom Configuration
If you need custom rules, you can create providers manually:
Performance
The library is optimized for speed:
- Pre-compiled regex patterns (no runtime compilation)
- Efficient URL parsing and rebuilding
- Minimal memory usage
- Suitable for bulk URL cleaning operations
Run performance benchmarks:
Architecture
Core Components
-
ClearUrls.php - Main cleaning logic
- URL parsing and validation
- Provider matching
- Rule application
- URL rebuilding
-
Provider.php - Rule provider data structure
- Pattern matching
- Exception handling
- Redirection extraction
-
ClearUrlResult.php - Immutable result object
- Cleaned URL
- Modification status
- Action flags
- Rules.php - Auto-generated (205 providers, 734+ rules)
- Pre-compiled regex patterns
- Optimized data structure
- Generated by build script
Build System (For Package Maintainers)
compile-rules.php - Rules compilation script (used by package maintainers to update rules)
- Fetches from https://rules2.clearurls.xyz/data.minify.json
- Compiles all regex patterns
- Generates optimized PHP code (src/Rules.php)
- Caches rules locally for offline builds with
--localflag
How It Works
- Build Time (package maintainers only): The build script fetches rules from ClearURLs and compiles them to PHP with pre-compiled regex patterns
- Runtime (end users): When cleaning a URL:
- Finds matching provider by URL pattern
- Checks exceptions (URLs that should not be processed)
- Handles redirections (extracts embedded URLs)
- Applies raw rules (regex on entire URL)
- Removes matching query parameters and fragments
- Rebuilds the clean URL
Rules Format
Rules are fetched from the ClearURLs project. Each provider has:
urlPattern: Regex to match URLscompleteProvider: Block entire providerrules: Query/fragment parameters to removerawRules: Regex patterns to apply to entire URLreferralMarketing: Optional marketing parametersexceptions: URLs to skipredirections: Extract embedded URLsforceRedirection: Force redirect behavior
See ClearURLs documentation for details.
Updating Rules (For Package Maintainers)
The pre-compiled rules (src/Rules.php) are included in the package. End users don't need to update them.
For package maintainers: To update rules to the latest version from ClearURLs:
This fetches rules from https://rules2.clearurls.xyz/data.minify.json and regenerates src/Rules.php.
The build script compares the SHA-256 hash of fetched rules against the previous version:
- Rules changed: Updates
updatedAttimestamp in metadata โ triggers new release - Rules unchanged: Preserves existing
updatedAttimestamp โ no new release
Use the --local flag to skip fetching and compile from cached rules:
Automated Rules Updates (GitHub Actions)
The repository includes a GitHub Actions workflow that automatically:
- Fetches the latest ClearURLs rules
- Compiles them to optimized PHP code
- Creates a new versioned release (format:
1.0.YYYYMMDD) - Updates the CHANGELOG
- Pushes to GitHub and creates a git tag for Packagist
To trigger an update:
- Go to the repository's "Actions" tab on GitHub
- Select "Update ClearURLs Rules" workflow
- Click "Run workflow" button
- The workflow fetches rules and checks if they changed (via SHA-256 hash)
- If rules changed AND version tag doesn't exist โ creates new release
- If rules unchanged โ keeps existing version, no duplicate release
Version format: x.y.YYYYMMDD where:
x.y= Major.Minor version (update manually when adding code features)YYYYMMDD= Date when rules were fetched from ClearURLs
This ensures Packagist automatically picks up new rule updates without manual intervention.
Project Structure
Testing
Install dev dependencies:
Run tests:
Supported Providers (205 total)
Major Providers
- Google (search, ads, redirects)
- Amazon (products, search, ads)
- Facebook (posts, redirects)
- YouTube (videos, tracking)
- Twitter/X (posts, tracking)
- LinkedIn (profiles, tracking)
- Reddit (posts, redirects)
- Instagram (posts, tracking)
- TikTok (videos, tracking)
- And 196+ more...
Global Rules
- UTM parameters (utm_source, utm_medium, etc.)
- Facebook tracking (fbclid)
- Google tracking (gclid, _ga)
- And many more tracking parameters
API Reference
ClearUrls Class
ClearUrlResult Class
Provider Class
Contributing
Contributions are welcome! Areas for contribution:
- Performance optimizations
- Additional test cases
- Documentation improvements
- Bug fixes
- Feature requests
Credits
- Original Project: ClearURLs by KevinRoebert
- Rules: Maintained by ClearURLs community
- PHP Implementation: klkvsk
License
MIT License
The rules data is provided by the ClearURLs project and is licensed under LGPL-3.0-or-later.
Links
- GitHub: https://github.com/klkvsk/clearurls-php
- Packagist: https://packagist.org/packages/klkvsk/clearurls
- ClearURLs Docs: https://docs.clearurls.xyz/
- Issue Tracker: https://github.com/klkvsk/clearurls-php/issues