php - Automatic indentation of HTML output? -


I want to automatically point out the output HTML via PHP scripts.

I take the HTML Purifiers for internal textbox input form verification, and HTMLTidy in mind, however, since HTML depends on pure HTML clean, which has not been actively developed and has many bugs in it. Reported, I was looking for something else.

I have found:

Is this a good option? - Is there any way to process another script or output?

As I am indenting in a fairly laborious way, for example (the part of the function that takes the indentation argument):

  Repeat str_repeat (" \ T ", $ indentation). "& Lt; ul & gt; \ n"; Foreign currency ($ value as $ value) {echo str_repeat ("\ t", $ indentation) "\ t 
  • . Datetime_converter ($ value ["date"]). "-" $ value ["paragraph"] "& lt; / li & gt; \ n"; } Echo str_repeat ("\ t", $ indentation) "& lt; / ul & gt;";
  • Thanks!

    This is my indentation function, it is expected that helps.

      class Html {private static $ _indent = ""; Individual static function indentStr ($ indent = 0) {$ replaceindent = null; // sets indentation for current indentvalue ($ o = 0; $ o  $ ExactTextView) {if (! Trim ($ unfixedtextvalue)) {continue; } $ Unfintextv = = '& lt;' . ($ Unfixedtextvalue) trim; / / Ensures that the blank rows are ignored (Preg_match ("/ ^ (\ s) * $ /", $ unfixedtextvalue) {$ fixedtextvalue = preg_replace ("/> (\ s | \ t) * $ SettextValue;}} // set not indentation $ indent level = 0; foreach ($ uncleanhtml_array) As $ uncleanhtml_key => $ currentuncleanhtml) {// Removes all indentions $ currentuncleanhtml = preg_replace ("/ \ t + /", "", $ currentuncleanhtml); $ Currentuncleanhtml = preg_replace ("/ ^ \ s + "," ", $ Currentuncleanhtml); $ replacement = es :: Indentstor ($ Indentaleval); // Automatically closing tag, if you apply the indent, then (preg_match ("/. & Lt; (+ /) \ />," $ currentuncleanhtml) {$ Cleanhtml_array [$ uncleanhtml_key] = $ replaceindent $ currentuncleanhtml.} Else if (preg_match ("/ & lt;. (*) & Gt; / $, $ currentuncleanhtml)) {// doctype declaration, then apply just clean $ cleanhtml_array [ $ Uncleanhtml_key] = $ replaceindent $ currentuncleanhtml } Else if (preg_match ("/. & Lt; [^ \ /] (*) & gt; /", $ currentuncleanhtml) & amp; amp; amp; preg_match ("/. & Lt; \ / (*) & gt; ; / ", $ Currentuncleanhtml)) {// If there is a tag to open and close on the same line, just apply indent $ cleanhtml_array [$ incorrectflag_key] = $ substitution. $ Currentuncleanhtml; } And if (preg_match ("/ / lt; / /. () & Gt; /", $ currentuncleanhtml) | preg_match ("/ ^ (\ s | \ t) * \} {1} (\ s | T) * $ / ", $ Currentuncleanhtml) {// If closing the HTML tag or closing the JavaScript clam, reducing the indentation and then applying the new level $ indentelvel; $ Replacement = self: indentst ($ indentlevel); $ Cleanhtml_array [$ uncleanhtml_key] = $ replacement $ Currentuncleanhtml; } And if ((preg_match ("/ / lt; [^ \ /] (. *) & Gt; /", $ currentuncleanhtml) & amp; Preg_match ("/ & lt; (link | meta | support | br | Img | hr | \?) (. *) & Gt; $, $ currentuncleanhtml) | preg_match ("/ ^ (\ s | \ t) * \ {{}} (\ s | \ t) * $ / ", $ Currentuncleanhtml)) {// If opening an HTML tag and not having a stand-alone tag, or opening a JavaScript clam, increase indentation, and then apply the new level $ cleanhtml_array [$ daphphic_key] = $ substitution. $ Currentuncleanhtml ; $ Indentlevel ++; $ replacement = self: indentstor ($ indentleval);} Else {// other, only $ Indianet $ Cleanhtml_array [$ uncleanhtml_key] = $ replacement. $ Currentuncleanhtml;}} Return a single string separated by the new line return implode ("\ n", $ cleanhtml_array);}}  

    And you say it like this:

      HTML :: Indent ($ Detachable);  

    Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -