snipt

Ctrl+h for KB shortcuts

PHP

clean filename

1
2
3
4
<?php

// clean filename:
$filename = preg_replace("/[^a-z0-9\-\.]/i", "_" , $filename); 
https://snipt.net/embed/d0742c5953ff7f605e76470beec9f31c/
/raw/d0742c5953ff7f605e76470beec9f31c/
d0742c5953ff7f605e76470beec9f31c
php
PHP
4
2019-07-22T19:25:49
True
False
False
/api/public/snipt/30588/
clean-filename
<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> <a href="#L-4">4</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;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// clean filename:</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$filename</span> <span class="o">=</span> <span class="nb">preg_replace</span><span class="p">(</span><span class="s2">&quot;/[^a-z0-9\-\.]/i&quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span> <span class="p">,</span> <span class="nv">$filename</span><span class="p">);</span> </span></pre></div> </td></tr></table>
clean, file, image, php, upload

PHP

POST: clean email field

1
2
3
4
<?php

// clean for email field
$email = preg_replace("/[^[email protected]\-_\.]/", "", $_POST['email']);
https://snipt.net/embed/0c467e66a9e431c5541ba77eba830332/
/raw/0c467e66a9e431c5541ba77eba830332/
0c467e66a9e431c5541ba77eba830332
php
PHP
4
2019-07-22T15:09:31
True
False
False
/api/public/snipt/23897/
post-clean-email-field
<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> <a href="#L-4">4</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;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// clean for email field</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$email</span> <span class="o">=</span> <span class="nb">preg_replace</span><span class="p">(</span><span class="s2">&quot;/[^[email protected]\-_\.]/&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="nv">$_POST</span><span class="p">[</span><span class="s1">&#39;email&#39;</span><span class="p">]);</span> </span></pre></div> </td></tr></table>
clean, email, form, post