preserving the <b> </b&gt tags

Hi,

Im using the following code to edit an xml file on my server:

<html>
<head>
<script type="text/javascript">

function insertString(el,str){
// Mozilla XUL extensions to the DOM    
if(typeof el.selectionStart=='number')
el.value=el.value.slice(0,el.selectionStart)+str+el.value.slice(el.selectionEnd,el.value.length);
// IE    
else if(document.selection){
el.focus();
document.selection.createRange().text=str;
}
// no support    
else el.value+=str
}

</script>
</head>
<body>
<?php
$XMLfile = "content.xml";
if(isset($_POST['submit'])){ // Saving data

    $fh = fopen($XMLfile,"w");
    fwrite($fh,stripslashes($_POST['fileContent']));
    fclose($fh);
    echo "Data saved in $XMLfile";
}
else{  // Show form
    $fh = fopen($XMLfile,"r");
    $data = fread($fh,filesize($XMLfile));
    fclose($fh);
   ?>
    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea id="fileContent" name="fileContent" cols="50" rows="30"><? echo $data; ?></textarea>
     <input type="button" value="Bolden Text" onclick="insertString(document.getElementById('fileContent'),'&lt;b&gt; &lt;/b&gt;')">
    <input type="submit" name="submit" value="Save" onClick="return confirm('Click OK to save the data')">
  </form>
    <?
}
?>
</body>
</html>

in this section of code:

 <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea id="fileContent" name="fileContent" cols="50" rows="30"><? echo $data; ?></textarea>
     <input type="button" value="Bolden Text" onclick="insertString(document.getElementById('fileContent'),'&lt;b&gt; &lt;/b&gt;')">
    <input type="submit" name="submit" value="Save" onClick="return confirm('Click OK to save the data')">
  </form>

I im using javascript to insert the &lt;b&gt; &lt;/b&gt; tags to the text area. my problem is that when i clcik the button these tags appear as the <b> </b> which doesnt work for me. i need them in the escape character format.

any ideas how i might resolve this?

thanks
LVL 2
clonmelogAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

clonmelogAuthor Commented:
ive been told that a function called htmlentities could help me here.... im ot too sure though!
0
RoonaanCommented:
You can then use

&amp;gt; and/or &amp;lt;

-r-
0
xberryCommented:
You have to escape the & sign itself first.
So put this sequence as your string instead of '&lt;b&gt; &lt;/b&gt;' :

'&amp;lt;b&amp;gt; &amp;lt;/b&amp;gt;'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
clonmelogAuthor Commented:
but doesnt this just create <> tags? how does this prevent the <b></b> appearing?

0
clonmelogAuthor Commented:
ill try that now:

You have to escape the & sign itself first.
So put this sequence as your string instead of '&lt;b&gt; &lt;/b&gt;' :

'&amp;lt;b&amp;gt; &amp;lt;/b&amp;gt;'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.