$test = "!!! sdfsdf sd$$$fdf ___";
$test = str_replace(' ', '_', $test); // Turn all spaces into underscores.
echo $test."<br />"; // Output: !!!___sdfsdf___sd$$$fdf______
$test = preg_replace('/[^a-zA-Z0-9_-]/', '-', $test); // Replace anything that isn't alphanumeric, or _-, with a hyphen.
echo $test."<br />"; // Output: !!!___sdfsdf___sd---fdf______
$test = preg_replace('/([_-])\1+/', '$1', $test); // Reduce multiple _- in a row to just one.
echo $test."<br />"; // Output: !_sdfsdf_sd-fdf_
Yukarıdaki kod ben şu anda ne var, ne için regex anlamaya çalışıyorum uçlarındaki herhangi bir alfasayısal olmayan karakterler kesmek için nasıl. Yani "! _sdfsdf_sd-Fdf_" için "sdfsdf_sd-fdf" nihai çıktı dönüyor.