<?php
function SilentGhost($z){
$z = strtolower($z);
$z = preg_replace('/[^a-z0-9 -]+/', '', $z);
$z = str_replace(' ', '-', $z);
return trim($z, '-');
}
function mario($z) {
return strtolower(trim(preg_replace("/[^\w]+/", "-", $z), "-"));
}
function Rooneyl($string) {
$new_string = preg_replace("/[^a-zA-Z0-9\s]/", "", $string);
$url = preg_replace('/\s/', '-', $new_string);
$new_url = urlencode($url);
return $new_url;
}
function AbhishekGoel($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
function HelloHack($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function DenisMatafonov($str) {
$withSpecCharacters = htmlspecialchars($str);
$splitted_str = str_split($str);
$result = '';
foreach ($splitted_str as $letter){
if (strpos($withSpecCharacters, $letter) !== false) {
$result .= $letter;
}
}
return $result;
}
function AdeelRazaAzeemi($str) {
$str = str_replace(' ', '-', $str);
$str = preg_replace('/[^\x20-\x7E]/', '', $str);
return $str;
}
function mickmackusa($string) {
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($string)), '-');
}
$strings = [
'This, is - - the URL!',
'Mork & Mindy',
'What the_underscore ?!?'
];
$funcs = ['SilentGhost', 'mario', 'Rooneyl', 'AbhishekGoel', 'HelloHack', 'DenisMatafonov', 'AdeelRazaAzeemi', 'mickmackusa'];
foreach ($strings as $string) {
echo "\n---\n" . var_export($string, true) . "\tinput\n";
foreach ($funcs as $func) {
echo var_export($func($string), true) . "\t$func\n";
}
}
preferences:
25.98 ms | 414 KiB | 5 Q