I need the following 3 line Ruby snippet to be transformed to PHP
text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
x.gsub(/^(.+)$/, "\1 ")
The PHP function should perform in exactly the same way. 30$ maximum and do not send any references etc. instead please confirm that you are able to transform the code in the private message.