$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_
위의 코드는 현재 내가 가지고있는 것으로, REGEX를 알아 내려고하는 것은 끝에서 영숫자가 아닌 문자를 어떻게 잘라내는지입니다. 따라서 최종 출력을 "! _sdfsdf_sd-fdf_"에서 "sdfsdf_sd-fdf"로 변경하십시오.REGEX (PHP에서) .. 끝에서 영숫자가 아닌 문자를 제거 하시겠습니까?
와우, 고마워. 나는 트림을 잊어 버린 것을 믿을 수 없다. – nkspartan