HTML-Reducer

Meik Schmidt shared this idea 8 months ago
Under Consideration

Hello


i have manually included a HTML-reducer. I wish this function as standard.


  1. // HTML-Ausgabe reduzieren
  2. // Ausgabepufferung für die HTML reduzierung
  3. ob_start("reduce");
  4. // Funktion zur Entfernung von ...
  5. function reduce($delete)
  6. {
  7. // ... HTML-Kommentare
  8. $delete = preg_replace("/<!--[^>]*-->/", "", $delete);
  9. // ... CSS-Kommentare
  10. $delete = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $delete);
  11. // ... Tabs, Leerzeichen und Zeilenumbrüche
  12. $delete = str_replace(array("\r\n", "\r", "\n", "\t", "\s",), "", $delete);
  13. // ... Reduzierung ausgeben
  14. return $delete;
  15. }

Comments (1)

photo
1

Nice idea and practical for any site wanting to reduce unnecessary rendering code with any script - not just Koken. To help to understand the objective of the code above, here's an English-translated version:


  1. // Reduce HTML output
  2. // Output buffering for HTML reduction
  3. Ob_start ("reduce");
  4. // Function for removing ...
  5. Function reduce ($ delete)
  6. {
  7. // ... HTML comments
  8. $ Delete = preg_replace ("/ <! - [^>] * -> /", "", $ delete);
  9. // ... CSS comments
  10. $ Delete = preg_replace ("! / \ * [^ *] * \ * + ([^ /] [^ *] * \ * +) * /!", "" $ Delete);
  11. // ... Tabs, spaces, and line breaks
  12. $ Delete = str_replace (array ("\ r", "\ r", "\ n", "\ t", "\ s")).
  13. // ... output reduction call
  14. Return $ delete;
  15. }