Okay, we could use regular expressions in php:
preg_replace('{\?+}', '?', 'Is this thing on??? or what???');
same for exclamation marks.
With javascript you could use:
var text = 'help??? test???';
var regex = /\?+/g;
var replaceWith='?';
text.replace(regex,replaceWith)