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 7843845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:41:16+00:00 2026-06-02T16:41:16+00:00

A user types any text in the textarea on html page. The string is

  • 0

A user types any text in the textarea on html page. The string is sent to the server using AJAX and returned back to <span id="userstring"></span>. Whatever was typed in the textarea, it is displayed in the span.
Everything works fine, but… When a user enters tags with a text, for example <b>hello</b>, it displays the bold word hello instead of <b>hello</b>.

So, the goal is to make THE MINIMUM CHANGES of the typed string, so it is displayed in span EXACTLY the same way as it was typed.

I decided the problem are < and > symbols, so my plan is replace them with &lt; and &gt;. In the span area will looks the same way as it was typed. Also, I should care of & symbol so when user types '&gt;' it looks &gt;, that’s why & should be replaced with &amp;.
Is there anything else I should take care of?
I don’t insert a string into the mysql db, so I don’t take any precautions of ‘ etc. But, I work with that string so I want to keep minimum changes of the string. Replacing &, < and > only are OK. Did I forget something?

Thank you.

  • 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-02T16:41:18+00:00Added an answer on June 2, 2026 at 4:41 pm

    Use htmlspecialchars()

    <php
    $string = '<b>bold text</b>';
    echo htmlspecialchars($string, ENT_HTML5, "UTF-8"); 
    ?>
    

    If you omit ENT_HTML5, it will default to ENT_HTML401 | ENT_COMPAT. In the above code, ENT_COMPAT is overridden so the quote character (") will not be escaped anymore.

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

Sidebar

Related Questions

If a textarea or input (type text) element has focus in a HTML page
I have an HTML form where the user can type in any number:5, 8,
if a user types in an input say 3 into a text box three
I'm creating a form where the user should be able to enter any text
Hey so I am trying to grab the user input text within a textarea
The user types some text. When they press a button, what they have typed
I have a page in which there are a few textarea and <input type=text>
Fellas, I am creating a text box dynamically, on a button click. User types
Android default browser doesn't fire OnKeyUp events on text inputs if user types non-latin
If a user types in [[0,0,0], [0,0,1], [1,1,0]] and press enter, the program should

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.