I want to insert some php code into a document, but I want first determine if I
am inside php tags. If I am then I will insert the php code without the php
tags. But if I am not inside the php tags then I will insert php code with the
tags.

For example if insertion point is:
<body>
<?php
|
?>
</body>

then insert echo "hello world";

But if the insertion point is
<body>
|
</body>

then insert:
<?php
echo "hello world";
?>

If it is possible then can you tell me which command I must use or point me in
the right direction?

Jeff