Tapeworms are made up of segments - these segments contain both male and female organs. When the organs "mate" the segment fills with eggs. When the segment is full of eggs - it will break away from the "mother" tapeworm.
As a tapeworm is dying - it will start releasing segemnts from the bottom end. It does this to try to survive the "poisons". Eventually you will see larger segments, then finally the head of the tapeworm will release it's grip from the intestinal wall, and will be removed.
The tapeworm attaches itself to the intestinal wall for support - it anchors there while it's body floats around. A tapeworm - like an earthworm - can regenerate itself if only it's head is left attached in the body.