snipt

Ctrl+h for KB shortcuts

PHP

regex - remove 2 or more whitespaces

1
2
3
<?
// remove multiple whitespaces
$line1 = preg_replace("/\s{2,}/", " ", $line1);
https://snipt.net/embed/27c291d423974a40bcf4f0a747ec99f4/
/raw/27c291d423974a40bcf4f0a747ec99f4/
27c291d423974a40bcf4f0a747ec99f4
php
PHP
3
2019-08-24T04:15:34
True
False
False
/api/public/snipt/8206/
regex-remove-2-or-more-whitespaces
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// remove multiple whitespaces</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$line1</span> <span class="o">=</span> <span class="nb">preg_replace</span><span class="p">(</span><span class="s2">&quot;/\s{2,}/&quot;</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="nv">$line1</span><span class="p">);</span> </span></pre></div> </td></tr></table>
php, regex, whitespaces