In the last case, you'll have to license the song in order to be absolutely legal. Now, assuming that you're going ahead, you'll first need a tool that will take an audio CD and capture part of it as digital data, so visit The Hit Squad and find the right tool for whatever platform you're on.
Good sound takes up a lot of space.
Nobody sane is going to download a 5-Mbyte file to hear 30 seconds' worth of audio, so the secret is either to compress it, or to really compress it. The closest thing to both a de facto audio standard and high-quality compression on the Web is RealAudio, and the site offers a free encoder. This program converts audio files to the compressed RealAudio .ram format. Now, even though you can also get a free RealAudio server, what many people don't realize is that you don't have to go to the trouble of streaming RealAudio just to make music clips available. All you have to do is take your .ram file and present it as if it were any other type of media, such as a graphics file.