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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:02:56+00:00 2026-06-13T00:02:56+00:00

I have generated PHP files for cache loading (via file_get_contents() or include() which randomly

  • 0

I have generated PHP files for cache loading (via file_get_contents() or include() which randomly procedures…) and let’s considere this example:

Un-optimized mode or uncached:

What I NOT want to see:

  • spaces between <body> and <head>
  • spaces between closed tags: /> <script or <table> <tr>

What I WANT to see (optimized way using PHP maybe PREG_REPLACE):

  • trimed spaces between tags <body><head>
  • trimed spaces between closed tags: /><script or <table><tr>

For above full example should be as RESULT such as:

<!DOCTYPE><head><link href="/static/css/main.css" rel="stylesheet" type="text/css"><title>Title</title><meta http-equiv='Content-Type' content='Type=text/html; charset=UTF-8'> <meta name="description" content="Description site" /><meta name="keywords" content="keywords, another keywords" /><script type="text/javascript" src="/static/js/jquerymin.js"></script></head><body><div id="center_box"><div id="orderdata"><table></table></div><div id="orderform"><form method="post" action="/frontacp" method="post" action="/frontacp" method="post" action="/frontacp" method="post" action="/frontacp"><div class="logincol"><div class="leftcol"><label for="types_name">Tip proizvoda</label></div><div class="rightcol"><input type="text" name="types_name" /></form></div></div></body></html>

Instead BAD (unoptimized usage) of page:

    <!DOCTYPE><head>
    <link href="/static/css/main.css" rel="stylesheet" type="text/css"><title>Title</title>
    <meta http-equiv='Content-Type' content='Type=text/html; charset=UTF-8'> <meta name="description" content="Description site" /><meta name="keywords" content="keywords, another keywords" /><script type="text/javascript" src="/static/js/jquerymin.js"></script></head>
    <body><div id="center_box">
        <div id="orderdata">
        <table>

        </table>
        </div>

        <div id="orderform">
        <form method="post" action="/frontacp" method="post" action="/frontacp" method="post" action="/frontacp" method="post" action="/frontacp"><div class="logincol"><div class="leftcol"><label for="types_name">Tip proizvoda</label></div><div class="rightcol"><input type="text" name="types_name"    /></form>    </div>
    </div></body></html>

Solutions: PHP example to trim this problem using in properly method and wan’t trim spaces inner HTML tags.

Notice: I have done about reading cache and rendering this question would not cover in this area.

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-13T00:02:57+00:00Added an answer on June 13, 2026 at 12:02 am

    This should work

    $document = preg_replace( '/\n/', '', $document );
    $document = preg_replace( '/>\s+</', '><', $document );
    $document = preg_replace( '/\s{2,}/', ' ', $document );
    

    Bye

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

Sidebar

Related Questions

I have various links on my site which are all generated via PHP MySQL
I have some php files in a server which generate xml code in them.
I have a JSON object which is generated by PHP. It's an object with
I have two checkboxes generated like this: <table> <?php foreach ($invited_members as $mem) :
I am trying to cache images which have been generated. You create a image
I have several CSS files generated in PHP. I change the current CSS file
I am trying to cache something. In my core.php config file, I have this:
I have a PHP site where all pages include an 57K generated PHP file.
How to generate jSon file via PHP? I have seen jSon files over 4mb
I have an array generated by PHP array( array( 'name'=>'node1', 'id' => '4' ),

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.