Note that there are some explanatory texts on larger screens.

plurals
  1. PORegular expression to convert/normalize multiline string to single string
    primarykey
    data
    text
    <p>The input is a multi-line string such as this:</p> <pre><code> table { border:0; border-spacing:0; border-collapse:collapse; margin-left:auto; // 'align:center' equivalent margin-right:auto; } </code></pre> <p>The output is a single-line string with "extra" whitespace &amp; comments removed, e.g.:</p> <pre><code> table { border:0; border-spacing:0; border-collapse:collapse; margin-left:auto;} </code></pre> <p>One way to do this with Perl is:</p> <pre><code> #! perl -w use strict; my $css = &lt;&lt;CSS; table { border:0; border-spacing:0; border-collapse:collapse; margin-left:auto; // 'align:center' equivalent margin-right:auto; } CSS $css =~ s/\s{2,}/ /g; # globally replace 2 or more whitespace with 1 space $css =~ s|\s+//.+\n||g; # globally replace C comment with empty string $css =~ s|\n||g; # globally replace newline with empty string print $css; </code></pre> <p>I tried doing something similar in PHP but it does <em>nothing</em> to the input:</p> <pre><code> &lt;?php define("CSS_TABLE", "table { border:0; border-spacing:0; border-collapse:collapse; margin-left:auto; // 'align:center' equivalent margin-right:auto; }"); $css = CSS_TABLE; preg_replace("/\s\s+/", ' ', $css); preg_replace("/\s+\/\/.+\n/", '', $css); preg_replace("/\n/", '', $css); echo("CSS-min: $css\n\n"); ?&gt; </code></pre> <p>Note: the 'define' isn't the issue because I also used a 'here' doc -- no joy either way. I'm showing the 'define' instead of a 'here' doc (as in the Perl example) because the existing PHP code uses it (and a whole bunch of others!).</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload