What are the potential pitfalls of using multiple str_replace functions in PHP to remove spaces before punctuation marks?

Using multiple `str_replace` functions to remove spaces before punctuation marks can be inefficient and error-prone, as each function call may not catch all instances of spaces before punctuation marks. A better approach is to use a regular expression with the `preg_replace` function to replace all occurrences of spaces before punctuation marks in one go.

$text = "Hello , World ! This is a test .";
$cleaned_text = preg_replace('/\s+([,.!?])/', '$1', $text);
echo $cleaned_text;