What you're looking for is a Number to Words converter. I suggest you use one of the existing solutions instead of trying to code it up yourself. Here's one using the convert_number_to_words
function from this blog:
$output = preg_replace_callback('~(\d+)~', function ($matches) {
return convert_number_to_words($matches[1]);
}, $testString);
Output:
startz[;thirty-onemendstartz[thirty-fivemend
The output is not exactly the same as in your question, but you could easily achieve this by modifying the function according to your requirements.