snipt

Ctrl+h for KB shortcuts

JavaScript

Fix broken images automatically

1
2
3
$('img').error(function(){
	$(this).attr('src', 'img/broken.png');
});
https://snipt.net/embed/11b46d468543c142594c407058013be4/
/raw/11b46d468543c142594c407058013be4/
11b46d468543c142594c407058013be4
js
JavaScript
3
2019-07-21T04:52:43
True
False
False
/api/public/snipt/109800/
fix-broken-images-automatically
<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="nx">$</span><span class="p">(</span><span class="s1">&#39;img&#39;</span><span class="p">).</span><span class="nx">error</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;src&#39;</span><span class="p">,</span> <span class="s1">&#39;img/broken.png&#39;</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>
broken, fix, image, img, jquery, placeholder

PHP

Check for pictures available by url

1
2
3
4
5
6
7
8
<?php
/* © AcidChristStudio, www.acidchrist.ru */

$image_url = 'http://site.com/folder/image.png';
$headers = @get_headers($image_url);
echo (strpos($headers[0], '200')) ? 'Exist;' : 'Not exist;';

?>
https://snipt.net/embed/bb7d41ec9d3c9ef0496fda381f133e03/
/raw/bb7d41ec9d3c9ef0496fda381f133e03/
bb7d41ec9d3c9ef0496fda381f133e03
php
PHP
8
2016-12-28T07:28:40
True
False
True
Sep 11, 2013 at 12:12 PM
/api/public/snipt/80363/
check-for-pictures-available-by-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></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="cm">/* © AcidChristStudio, www.acidchrist.ru */</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="nv">$image_url</span> <span class="o">=</span> <span class="s1">&#39;http://site.com/folder/image.png&#39;</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$headers</span> <span class="o">=</span> <span class="o">@</span><span class="nb">get_headers</span><span class="p">(</span><span class="nv">$image_url</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a><span class="k">echo</span> <span class="p">(</span><span class="nb">strpos</span><span class="p">(</span><span class="nv">$headers</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;200&#39;</span><span class="p">))</span> <span class="o">?</span> <span class="s1">&#39;Exist;&#39;</span> <span class="o">:</span> <span class="s1">&#39;Not exist;&#39;</span><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>
check, image