Flatulence-The prohibition to release gas while wearing Tefillin:
One who is gassy: Accordingly, one who is gassy is not to wear Tefillin until he is confident that he can wear the Tefillin even for a moment without releasing gas, as explained in Chapter 1 Halacha 7B.
Flatulating near Tefillin: Furthermore, some Poskim rule that it is forbidden to flatulate near uncovered Tefillin, even if they are not on him, but sitting next to him, as explained in Chapter 6 Halacha 9.
Restrictions implemented due to the prohibition: Likewise, due to this prohibition against flatulating while wearing Tefillin, and due to its severity, many restrictions were enacted as a guard railing to prevent this from happening, including the following restrictions: 1) It is forbidden to sleep while wearing tefillin lest one come to flatulate during his sleep. 2) It is forbidden to wear Tefillin at night lest one come to fall asleep and flatulate. 3) We are no longer accustomed to wearing Tefillin throughout the day as was done in previous times due to the difficulty in controlling oneself not to flatulate throughout the day. 4) It is forbidden to urinate while wearing tefillin lest one come to flatulate.
What to do if one feels the need to flatulate: If one is unable to withhold himself from flatulating, then he is to remove his Tefillin prior to doing so. If one is unable to remove his Tefillin on time, then he should at the very least move his Tefillin out from their valid position on the bicep and head, thus making it considered as if he is not wearing them. If he is unable to move both Tefillin on time, then at the very least, he is to remove his Tefillin Shel Rosh.
Tikkun for flatulating while wearing Tefillin:
Some Poskim suggest that if one flatulated while wearing Tefillin, then he must perform atonement similar to that which is required if the Tefillin fell on the floor.
If one is very gassy and is embarrassed to Daven with the Minyan without wearing Tefillin, what is he to do?
Some Poskim rule he may wear the Tefillin improperly during Davening, such as in their wrong area or with a Chatzitza.
If one moved the Tefillin from their proper area in order flatulate, must the blessing be repeated?
Some Poskim rule that if one moved the Tefillin from their proper area in order to release gas, the blessing must be repeated prior to re-placing the Tefillin by their proper area. Other Poskim, however, rule that a blessing is not to be repeated. Certainly, if one did not get a chance to remove the Tefillin from their area upon flatulating then the blessing is not to be repeated.
Educating Bar Mitzvah boys:
One is to educate Bar Mitzvah boys of the importance, and obligation, of keeping a clean body while wearing Tefillin, and that they may not flatulate while wearing them.
 Admur 80:3; 37:2 in parentheses; 43:1 [regarding urinating]; 44:1 [regarding prohibition to sleep a set sleep due to worry that one may flatulate]; Michaber 38:2; Rosh 4:8; See Piskeiy Teshuvos 37:2
 Simply speaking, this refers to all forms of flatulence, irrelevant of degree of noise or odor. [As rules Admur 103:3 regarding Shemoneh Esrei] However, some Poskim question that perhaps a soundless and odorless flatulence which is released under duress is not under the prohibition. [Ashel Avraham Butchach 38 regarding soundless; Od Yosef Chaiy Chayeh Sarah 4 regarding odorless; See Elya Raba 103:7; Beir Moshe 6:2; Teshuvos Vehanhagos 3:14; Halichos Shlomo 4 footnote 101 in name of Rav SZ”A; Piskeiy Teshuvos ibid footnote 12] Practically, one is to beware from all forms of flatulence.
 The reason: As Tefillin require a clean body. [Admur 37:2; 80:1; Shabbos 49a]
 Shagas Aryeh 40 “To flatulate is a Biblical prohibition due to Bizuiy Mitzvah”; See Ashel Avraham Butchach 38; Darkei Teshuvah Y.D. 28
 Ashel Avraham Butchach 38
 See Admur 80:3
Other opinions: Some Poskim rule that the prohibition against flatulence in Tefillin is only when one is sleeping, or intentionally, and not when one is gassy. [Toras Chaim Sofer 38:1 in name of Mor Uketzia; Kaf Hachaim 38:5]
 2nd opinion in Admur 44:1; Implication of Rashi Sukkah 26a; Raavad Tefillin 4:15; Sefer Hameoros Brachos 23b
 Admur 44:1; Rashi Sukkah 26a;
 Biblically one is obligated to wear Tefillin also at night. However, the Sages prohibited one from wearing Tefillin at night. because the nighttime is a time of sleep and the Sages thus decreed against wearing Tefillin lest one forget and come to sleep in them, and it is forbidden to sleep in Tefillin due to reasons explained in 44:1. [Admur 30:1; Michaber ibid; Rashi Eiruvin ibid] Now, there it is explained that it is forbidden to sleep in Tefillin lest one release bodily odors. [Admur 44:1]
 Admur 37:2; Michaber 37:2
 See Admur 43:1
 See M”B 103:3; Piskeiy Teshuvos 37:2; 38:1
 Ashel Avraham Butchach 38
 Minchas Yitzchak 6:13 based on Ashel Avraham 38 and 28
 Chayeh Adam, brought in M”B 25:47; Implication of Ketzos Hashulchan 8:18
 Afikei Maginim 25:32; See Piskeiy Teshuvos 25:23
 Rivivos Efraim 1:25