You have anal sphincter muscles which control the release of liquids, solids and gases. Your muscles adjust to the the pressure build up of either of the three states - and you release liquid, gas or solid. Sometimes the preesure build up is intense and you can choose to open the sphincter muscles and expel violently (*FARRRRRRRRRRRRRRTTTTTT*) or sometimes there is less gas, and you may choose to just *slip one out* (*Pfft*)
The solid matter is left over, undigested food (roughage) and the liquid matter (eg when you have diarrhoea) is the same, but with less water having been absorbed higher in your intestines.
The gas, ie farts, is simply a by product from the digested food particles left in your colon. Certain foods produce more gas, and different people also experience this differently.