- substr_replace: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = "Please ask your questions after the session is finished.";
preg_match_all('/\h+/', $str,$matches, PREG_OFFSET_CAPTURE);
$str = substr_replace($str, "\n", $matches[0][2][1], strlen($matches[0][2][0]));
echo $str;