1. Go to this page and download the library: Download klkvsk/clearurls library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
klkvsk / clearurls example snippets
use ClearUrls\ClearUrls;
// Create cleaner with default rules
$cleaner = ClearUrls::createDefault();
// Clean a URL
$result = $cleaner->clean('https://example.com/page?utm_source=twitter&id=123');
echo $result->url; // https://example.com/page?id=123
echo $result->wasModified ? 'Modified' : 'Unchanged'; // Modified
use ClearUrls\ClearUrls;
use ClearUrls\Provider;
$providers = [
new Provider(
name: 'custom',
urlPattern: '#^https?://example\.com#i',
completeProvider: false,
rules: [
'#^tracking$#i',
'#^session_id$#i',
],
rawRules: [],
referralMarketing: [],
exceptions: [],
redirections: [],
forceRedirection: false
),
];
$cleaner = new ClearUrls($providers);
// Create with default rules
$cleaner = ClearUrls::createDefault(bool $allowReferralMarketing = false): self
// Create with custom providers
$cleaner = new ClearUrls(array $providers, bool $allowReferralMarketing = false)
// Clean a URL
$result = $cleaner->clean(string $url): ClearUrlResult
// Set referral marketing preference
$cleaner->setAllowReferralMarketing(bool $allow): void
readonly class ClearUrlResult {
public string $url; // Cleaned URL
public bool $wasModified; // Was URL modified?
public bool $wasBlocked; // Was URL blocked?
public bool $wasRedirected; // Was URL redirected?
public function hadAnyAction(): bool; // Any action taken?
}
readonly class Provider {
public function __construct(
public string $name,
public string $urlPattern,
public bool $completeProvider,
public array $rules,
public array $rawRules,
public array $referralMarketing,
public array $exceptions,
public array $redirections,
public bool $forceRedirection
);
public function matchesUrl(string $url): bool;
public function getRedirection(string $url): ?string;
public function getAllRules(bool $