Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:38:29+00:00 2026-06-09T02:38:29+00:00

I am using a contenteditable <div> to edit an e-mail message (specifically, with NicEdit

  • 0

I am using a contenteditable <div> to edit an e-mail message (specifically, with NicEdit). I want to be able to submit the message body in a form, process it with PHP, and send it using the mail() function (or PHPMailer).

The problem I’m having is to do with special characters and encoding. When a special character such as π or á is typed into the div, it remains unchanged instead of being converted to an html entity like &pi; or &aacute;. There are some cases where it is converted, like < to &lt;.

So when the form is submitted, the data received by PHP is difficult to handle. Writing

pi is "less than" 2 × pi:
π < 2π

puts the following data in the contenteditable div

<div>pi is "less than" 2 × pi:</div>
<div>π < 2π</div>

and this is what is received by PHP. But using htmlentities() gives

&lt;div&gt;pi is &quot;less than&quot; 2 &times; pi:&lt;/div&gt;
&lt;div&gt;&pi; &lt; 2&pi;&lt;/div&gt;

which is correct except for the HTML tags, so this method appears to be useless. The originally received data is fine for inserting into a database (I think), but when I attempt to send it as an e-mail the encoding messes up.

From my point of view it seems like the solution is to encode the entities that are outside of HTML tags to get something like this:

<div>pi is &quot;less than&quot; 2 &times; pi:</div>
<div>&pi; &lt; 2&pi;</div>

but from searching on Google and StackOverflow this seems to be a bad thing to do. So I think I must be doing something wrong with the encoding at some point, whether that’s just before sending the e-mail or back with the original contenteditable data. I’m looking for a solution that works, ideally without some complicated library like HTMLPurifier.

Any ideas?

EDIT: I have tried this solution to convert special characters to html entities when they are not in tags. This seems to work well when I try typing in special characters like π. But the answer from that link has been voted down and a similar answer says the approach is fundamentally wrong. Can anyone tell me why this is, and why I shouldn’t stick with htmlentitiesOutsideHTMLTags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:38:31+00:00Added an answer on June 9, 2026 at 2:38 am

    Just an idea :

    • Step 1:
      Convert your <div> <b></b> </div> to [div] [b] [/b] [/div]
    • Step 2:
      You Htmlentities
    • Step 3: Convert your [div] [b] [/b] [/div] to <div> <b> </b> </div>

    By the way, I think that you can use strip_tags() before the step 1…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using contenteditable div elements in my web application and I am trying
I'm looking for a simple javascript html editor that support: using div(contenteditable) insteal of
I'm using a div with the contentEditable attribute to meet my need as a
I am using contentEditable div tags on my website and I have noticed a
I want to insert some html in a contenteditable div. When editing the content,
If i use <div contentEditable=true name=content></div> instead of Textarea in the form i'm not
i have a div with contenteditable=true that im using in place of textarea using
Can i apply css to selected text in a contenteditable div instead of using
I'm trying to write a wysiwyg editor using a contentEditable div, and am having
Currently I am making an editor using contenteditable. I have the following: <div contenteditable=true>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.