<?php

$text = "No? Oh ? And ! and!";
$text = preg_replace('~\s*([?!])~',  '&nbsp;$1', $text);
/*
$text =  str_replace(' ?', '?', $text);
$text = str_replace('?', '&nbsp;?', $text);
$text = str_replace(' !', '!', $text);
$text = str_replace('!', '&nbsp;!', $text);*/
echo $text;