Wow, some hideous advice being given here.
Your problem is not PHP but HTML. Somewhere in the HTML spec, they had the bright idea of not displaying more than one space. So you must insert the "& nbsp ;" character if you want to force the display of multiple spaces without using <pre></pre> tags.
Without actually changing your string, I would simply do this so that spaces are reformatted to non-breaking space (& nbsp 😉 characters.
$str="(10 spaces)hello";
echo str_replace(" ", " ", $str);
str_repeat is not what you need. They misinterpreted the question.