snipt

Ctrl+h for KB shortcuts

JavaScript

Get File Name from URL

1
2
3
var getFileName = function (url) {
    return url.replace(/\?.*$/, "").replace(/.*\//, "");
}
https://snipt.net/embed/dba4844455e27d7a020ba19ff08e3a49/
https://snipt.net/raw/dba4844455e27d7a020ba19ff08e3a49/
dba4844455e27d7a020ba19ff08e3a49
js
JavaScript
3
2016-09-24T07:11:05
True
False
False
Oct 05, 2015 at 11:03 AM
/api/public/snipt/141505/
get-file-name-from-url-40c6beb7
<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 id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">getFileName</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">url</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="nx">url</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\?.*$/</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/.*\//</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
filename, url

Text only

Quitar el .html de las urls por htaccess

1
2
3
#### Para quitar el .html de las urls
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
https://snipt.net/embed/ecacb9d931e0410ca9d5e738019a210a/
https://snipt.net/raw/ecacb9d931e0410ca9d5e738019a210a/
ecacb9d931e0410ca9d5e738019a210a
text
Text only
3
2016-09-22T01:45:36
True
False
False
Sep 30, 2015 at 10:01 AM
/api/public/snipt/141324/
quitar-el-html-de-las-urls-por-htaccess
<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 id="L-1"><a name="L-1"></a>#### Para quitar el .html de las urls </span><span id="L-2"><a name="L-2"></a>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/ </span><span id="L-3"><a name="L-3"></a>RewriteRule ^(.*)\.html$ /$1 [R=301,L] </span></pre></div> </td></tr></table>
htaccess, url

PHP

Validation d'une URL

1
2
3
4
5
6
7
8
<?php 
 
function is_valid_url($url){
    $p1 ='/(http|https|ftp):\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i';
    return preg_match($p1, $url); 
}

?>
https://snipt.net/embed/0526fe2e783e23c0c0c4a2b6512d398d/
https://snipt.net/raw/0526fe2e783e23c0c0c4a2b6512d398d/
0526fe2e783e23c0c0c4a2b6512d398d
php
PHP
8
2016-09-25T14:09:11
True
False
False
/api/public/snipt/102287/
validation-dune-url
<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> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><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="k">function</span> <span class="nf">is_valid_url</span><span class="p">(</span><span class="nv">$url</span><span class="p">){</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$p1</span> <span class="o">=</span><span class="s1">&#39;/(http|https|ftp):\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="nb">preg_match</span><span class="p">(</span><span class="nv">$p1</span><span class="p">,</span> <span class="nv">$url</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
url, validation

PHP

Validate if a string is a valid URL in PHP

1
2
3
4
<?php
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
  // echo('is valid!');
}
https://snipt.net/embed/59aaec0899ca3a6f5a750398f5121724/
https://snipt.net/raw/59aaec0899ca3a6f5a750398f5121724/
59aaec0899ca3a6f5a750398f5121724
php
PHP
4
2016-09-25T23:59:58
True
False
False
Jan 27, 2014 at 02:37 AM
/api/public/snipt/102097/
validate-if-a-string-is-a-valid-url-in-php
<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 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="k">if</span> <span class="p">(</span><span class="nb">filter_var</span><span class="p">(</span><span class="nv">$url</span><span class="p">,</span> <span class="nx">FILTER_VALIDATE_URL</span><span class="p">)</span> <span class="o">!==</span> <span class="k">false</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// echo(&#39;is valid!&#39;);</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
php, url, validation
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.