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

  • Home
  • SEARCH
  • 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 6345507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:50:11+00:00 2026-05-24T20:50:11+00:00

How could I convert everyting between a tag to html enities: Lorem ipsum dolor

  • 0

How could I convert everyting between a tag to html enities:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua.
<code class="highlight sql">
    CREATE TABLE `comments`
</code>

<h1>Next step</h1>

Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum.
<b>Stet clita kasd gubergren, no sea takimata sanctus</b> est Lorem
dolor sit amet. Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat, sed diam voluptua:
<code class="highlight php">
    <?php
        $host = "localhost";
    ?>
</code>

Lorem ipsum dolor sit amet, consetetur sadipscing elitr.

Note: That example above is a string which I could convert in PHP.

  • 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-05-24T20:50:12+00:00Added an answer on May 24, 2026 at 8:50 pm

    This comes down to a regex for me. And before you start shouting it is possible to reliably match & replace subsets of html, as long as there are no nesting tags.

    This is the easy way tbh. A regex to match a tag start till end and apply a function to the matches / encoding what we need and replacing it.

    Heres the code:

    <?php
    $string = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
    sed diam nonumy eirmod tempor invidunt ut labore et dolore
    magna aliquyam erat, sed diam voluptua.
    <code class="highlight sql">
        CREATE TABLE `comments`&
    </code>
    
    <h1>Next step</h1>
    
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
    sed diam nonumy eirmod tempor invidunt ut labore et
    dolore magna aliquyam erat, sed diam voluptua.
    At vero eos et accusam et justo duo dolores et ea rebum.
    <b>Stet clita kasd gubergren&, no sea takimata sanctus</b> est Lorem
    dolor sit amet. Lorem ipsum dolor sit amet, consetetur
    sadipscing elitr, sed diam nonumy " eirmod " tempor invidunt
    ut labore et dolore magna aliq&uyam erat, sed diam voluptua:
    <code class="highlight php">
        <?php
           * $host = "localhost";
        ?>&
    </code>
    
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr.';
    
    echo preg_replace("/(<code[^>]*?>)(.*?)(<\/code>)/se", "
        stripslashes('$1').
        htmlentities(stripslashes('$2')).
        stripslashes('$3')
    ", $string);
    

    And heres a working testcase on codepad

    http://codepad.org/MhKwfOQl

    This will work as long as there are no nasty nested tags / corrupted html.

    I would still advise you to try and make sure you save the data as you want to make it visible, encoded where needed.

    If you want to replace between a different set of tags change the regex.

    Update: It seemed that $host was being parsed by php… and ofrourse we don’t want this. This happened because php evaluates the replacement string as php which then executes the given functions and inputs the found strings into those functions, and if that string is encapsulated by double qoutes it will parse those strings too… heh what a hassle.

    And another problem then arises, php escapes single and double qoutes in matches so they won’t generate parse errors, this ment that any qoutes in the matches had to be stripped from their slashes too… resulting in the pretty long replace string.

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

Sidebar

Related Questions

I'm searching for a free component or library that could convert HTML to PostScript
Anyone know of a nice efficient function that could convert, for example: HelloWorld -->
Convert angle in degrees to a point How could I convert an angle (in
How could I merge / convert multiple PDF files into one large PDF file?
Is there something available that could help me convert a XSD into SQL relational
How can I convert xml to java so that it could read the xml
Can anyone recommend a good application that could be used to convert VB.NET projects
In the following snippet my intention is to convert a System.Object (which could be
I need to convert a HashMap<String, Object> to an array; could anyone show me
I would be appreciative if someone could explain to me the difference between the

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.