Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Cleans up file names, strips invalid characters

$filename = preg_replace('/[^0-9a-z\.\_\-]/i','',$original_filename);
https://snipt.net/embed/ab00a416fb98ce5032c1f64c1ac5d937/
https://snipt.net/raw/ab00a416fb98ce5032c1f64c1ac5d937/
ab00a416fb98ce5032c1f64c1ac5d937
php
PHP
1
2016-12-08T21:36:15
True
False
False
/api/public/snipt/9408/
cleans-up-file-names-strips-invalid-characters
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">$filename = preg_replace(&#39;/[^0-9a-z\.\_\-]/i&#39;,&#39;&#39;,$original_filename);</span> </span></pre></div> </td></tr></table>
file, filename, name, strip

PHP

returns just the filename from a path string

1
2
3
$name = "somefilenamestring.php";
$ext = strrchr($name, '.');
if($ext !== false) $name = substr($name, 0, -strlen($ext));
https://snipt.net/embed/9819e07cc1fd777c9f274ae4dd9354d2/
https://snipt.net/raw/9819e07cc1fd777c9f274ae4dd9354d2/
9819e07cc1fd777c9f274ae4dd9354d2
php
PHP
3
2016-12-04T16:05:40
True
False
False
/api/public/snipt/9364/
returns-just-the-filename-from-a-path-string
<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="x">$name = &quot;somefilenamestring.php&quot;;</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$ext = strrchr($name, &#39;.&#39;);</span> </span><span id="L-3"><a name="L-3"></a><span class="x">if($ext !== false) $name = substr($name, 0, -strlen($ext));</span> </span></pre></div> </td></tr></table>
extension, file, filename, name, strip
Copyrighted, illegal, or inappropriate content? Email [email protected].