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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:35:19+00:00 2026-06-08T18:35:19+00:00

I am just trying to replace html brackets with their ascii equivalent. Particularly <

  • 0

I am just trying to replace html brackets with their ascii equivalent. Particularly < for &lt; and > for &gt; for code inside a pre tag.

There must be a very simple script to do this but I can`t find it.

Something along the lines of the code below except something that works.

$('.code').each(function() {
var $this = $(this);
var t = $this.html();
$this.html(t.replace('/</g','&lt;').replace('/>/g','&gt;'));
});

Any help would be much appreciated.

  • 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-08T18:35:20+00:00Added an answer on June 8, 2026 at 6:35 pm

    You should do validation/replacing of < and > server-side using PHP etc. as people can easily disable JavaScript and evade validation that is client-side. Client-side validation is like saying for a stranger to look after your wallet. Sometimes the stranger will be a nice person and not open it. Sometimes they may be a thief.

    Anyway, here is a PHP example:

    <?php
    $raw = $_POST['text'];
    $encoded = htmlentities($raw);
    // Use the below code if you are inserting the result into a database
    $db_encoded = mysqli_real_escape_string($conn, $encoded);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying replace two consecutive line breaks with the HTML tag <p/> . So
just trying to test for equality in this piece of code, but getting a
Just trying to confirm an impression: it seems enums in EF5 + Code First
I'm trying to replace a small part of text in a large HTML document
I am trying to replace a CSS style in the following code: var theHTML
Im trying to replace the html of emoticon (the image) in to plain text.
I have an HTML table in my page that I'm trying to replace with
I'm trying to decode HTML entities (in the format &#39; ) in C. So
I'm trying to parse strings that represent source code, something like this: [code lang=html]
I'm trying to write a search and replace regex that will detect whether HTML

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.