There is a string of arbitrary length and content, it often comes across inserts of several repeated question marks, the number of characters can be different, how ?? , so and ???????? and ???? , etc.

Tell me, please, how can I remove such inserts from a line if there is more than one question mark in a row?

    1 answer 1

    1. If you need to remove duplicate question marks:

       $str = '??? ?? ??'; $str = preg_replace('/(\?){2,}/', '$1', $str); //echo $str вернет ? ? ? 
    2. If it is necessary to cut out question marks from the line, when their number is more than one:

       $str = 'example ? example1 ??? example2 ?? example3 ??'; $str = preg_replace('/\?{2,}/', '', $str); //echo $str вернет example ? example1 example2 example3