Legendre Example from the worked problems in my lecture notes

A0 = 1 - 1/E
A2 = 25/2 - 35/E

f[x_] = A0 LegendreP[0,x] + A2 LegendreP[2,x]

Plot[{Exp[-Abs[x]],f[x]},{x,-1,1}]

That' s just with two terms.  Now look at the general case and let Mathematica do the integrations for you

g[x_] = Exp[-Abs[x]];
A[l_] :=(2l +1)/2 Integrate[g[x] LegendreP[l,x],{x,-1,1}]

h[x_] = Sum[A[l]LegendreP[l,x],{l,0,5}]

Plot[{g[x],h[x]},{x,-1,1}]

Compare with a Fourier Series

<<FourierSeries`
k[x_] = FourierTrigSeries[g[x],x,2,FourierParameters->{1,.5}]

Plot[{g[x],h[x],k[x]},{x,-1,1}]

BUT :  The fourier series givess you the periodic extension of the function, while polynomials must blow up for large x

Plot[{g[x],h[x],k[x]},{x,-3,3}]