snipt

Ctrl+h for KB shortcuts

PHP

PHP time date setting

1
2
3
4
5
6
<?php
    //date_default_timezone_set('EST'); 
    date_default_timezone_set('America/Chicago');
    echo date('h:i', $_SERVER['REQUEST_TIME']) . '<br/>';
    echo date('m-d-Y h:i a e O P T', strtotime('now'));
?>
https://snipt.net/embed/a0e81b6998729c956958214233b41820/
/raw/a0e81b6998729c956958214233b41820/
a0e81b6998729c956958214233b41820
php
PHP
6
2019-07-21T14:42:19
True
False
False
/api/public/snipt/31136/
php-time-date-setting
<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> <a href="#L-5">5</a> <a href="#L-6">6</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 class="c1">//date_default_timezone_set(&#39;EST&#39;); </span> </span><span id="L-3"><a name="L-3"></a> <span class="nb">date_default_timezone_set</span><span class="p">(</span><span class="s1">&#39;America/Chicago&#39;</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">echo</span> <span class="nb">date</span><span class="p">(</span><span class="s1">&#39;h:i&#39;</span><span class="p">,</span> <span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;REQUEST_TIME&#39;</span><span class="p">])</span> <span class="o">.</span> <span class="s1">&#39;&lt;br/&gt;&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nb">date</span><span class="p">(</span><span class="s1">&#39;m-d-Y h:i a e O P T&#39;</span><span class="p">,</span> <span class="nb">strtotime</span><span class="p">(</span><span class="s1">&#39;now&#39;</span><span class="p">));</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
date, php, time

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