python_q - when you make the iframe you do this:
function RTFActivate() {
editwindow.document.designMode = "On";
}
which makes it realise that you are using the iframe as a rich text editor, you then use cmdexec for the functions - hence you are limited in what functions you can offer. With RTF editing mode on it behaves just like a normal RTF editor, so the highlighted code/text has html tags placed around it. It just puts <b> at the start of the highlight and </b> at the end for example.
Here is an example of basically the same thing I created about a year ago for asp (would work exactly the same on PHP as its JS)
http://www.prodtrac.com/dumbonion/CM_FILE_GURU.asp?pagefunction=create
You cant see it on that one, but you can also swap to designmode.off in the RTF window (iframe) and show innerhtml.on which shows you all the html tags in place. HTH.