How to replace multiple consecutive question marks (?) with a single question mark in PHP

1 Answer

0 votes
$str = "Hello??? How are you?? What is your Wi-Fi password????";

// Replace multiple '?' with a single '?'
$result = preg_replace('/\?+/', '?', $str);

echo $result; 




/*
run:

Hello? How are you? What is your Wi-Fi password?

*/

 



answered Jul 23, 2025 by avibootz
...