Clear[n,m]

n = 9; m =8;

fac[x_]= FullSimplify[LegendreP[n, m, Cos[x]]]

fac[x_]=FullSimplify[LegendreP[n,m,Cos[x]]/Sin[x]^(2*n+1)]

intfac[x_]= Integrate [fac[x],x]

multi =FullSimplify[ -((-1)^m)*((2*n+1)*(n-m)!/(n+m)!)^0.5* m]*Sin[phi]^(2*n-1)

FortranForm[multi*intfac[x]]

fac[x_]=FullSimplify[LegendreP[n,m,Cos[x]]/Sin[x]^(2*n+1)]

t[phi_] := ((2*n + 1)*((n - m)!/(n + m)!))^0.5*m

*Sin[phi]^(2*n)*
    Integrate[LegendreP[n, m, Cos[x]]/Sin[x]^(2*n + 1), {x, phi, Pi/2}];