Skip to content

Instantly share code, notes, and snippets.

@sepiariver
Last active December 30, 2019 08:35
Show Gist options
  • Save sepiariver/a9cb948915fd949bd836f049512cfccb to your computer and use it in GitHub Desktop.
Save sepiariver/a9cb948915fd949bd836f049512cfccb to your computer and use it in GitHub Desktop.
<?php
$input = $modx->getOption('input', $scriptProperties, '', true);
$output = $modx->getOption('options', $scriptProperties, '', true);
$classnames = explode(' ', $input);
$results = [];
foreach ($classnames as $token) {
// Strip out any % encoded octets
$normalized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $token);
// Replace _ with - and lowercase for old times' sake
$normalized = str_replace('_', '-', strtolower($normalized));
// Limit to a-z,0-9,-
$normalized = preg_replace('/[^a-z0-9-]/', '', $normalized);
// Remove numeric starting characters
$normalized = ltrim($normalized, '0123456789-');
if (empty($normalized)) continue;
$results[] = $normalized;
}
if (!empty($results)) $output = implode(' ', $results);
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment