Generate code that has the following intention.

The intention of the p1 function is to split a given list of words into a list of phases, where each phase is a substring of the input list starting from the first word and ending at the last space before the poles index. If there are no more spaces in the input list, the function will append the remaining words as the last phase. The function returns the resulting list of phases.