Check whether image exists on remote server

Here is example to verify whether given image exists on server or not. For that we can use PHP inbuilt function get_headers() .

get_headers — Fetches all the headers sent by the server in response to an HTTP request. get_headers function return an array with the headers sent by the server in response to a HTTP request.

<?php

$url = "http://blogs.ptutorial.com/wp-content/uploads/2015/08/logo_php5.png";

function checkImageExist($url){
$headers = get_headers($url, 1);
$status="";
if (strpos($headers['Content-Type'], 'image/') !== false) {
    $status=1;
} else {
    $status=0;
}   
return $status;
}
?>

The output of the get_headers function:

Array
(
    [0] => HTTP/1.1 200 OK
    [x-amz-id-2] => c/RpQuXgUvK8Fv6zMa2XIwjYfBMooqSmLBrbfyFRhfmEplvtZht0nI8iHxuQk7DysAFPlagkk6A=
    [x-amz-request-id] => A0FE2FA39A7860A3
    [Date] => Sat, 09 Feb 2019 05:17:40 GMT
    [Last-Modified] => Wed, 11 Jul 2018 20:16:46 GMT
    [ETag] => "7954ed8ca909c136bce3c762733df482"
    [Accept-Ranges] => bytes
    [Content-Type] => image/jpeg
    [Content-Length] => 37934
    [Server] => AmazonS3
    [Connection] => close
) 



Limit Select2 to one selection per optgroup with multiple selection

Here is a example to create multiple select with grouped multiple select where you can select one option per group.

HTML code

<pre class="wp-block-syntaxhighlighter-code">
&amp;lt;select multiple style=&quot;width: 300px&quot;&gt;
  &amp;lt;optgroup label=&quot;Alaskan/Hawaiian Time Zone&quot;&gt;
    &amp;lt;option groupid=&quot;a&quot; value=&quot;AK&quot;&gt;Alaska&amp;lt;/option&gt;
    &amp;lt;option groupid=&quot;a&quot; value=&quot;HI&quot;&gt;Hawaii&amp;lt;/option&gt;
  &amp;lt;/optgroup&gt;
  &amp;lt;optgroup label=&quot;Pacific Time Zone&quot;&gt;
    &amp;lt;option groupid=&quot;b&quot; value=&quot;CA&quot;&gt;California&amp;lt;/option&gt;
    &amp;lt;option groupid=&quot;b&quot; value=&quot;NV&quot;&gt;Nevada&amp;lt;/option&gt;
    &amp;lt;option groupid=&quot;b&quot; value=&quot;OR&quot;&gt;Oregon&amp;lt;/option&gt;
    &amp;lt;option groupid=&quot;b&quot; value=&quot;WA&quot;&gt;Washington&amp;lt;/option&gt;
  &amp;lt;/optgroup&gt;

&amp;lt;/select&gt;
</pre>

JavaScript Code


$(function() {
    $('select').select2({
      allowClear: true,
      placeholder: "Pick a State"
    });

    //Select2 Event handler for selecting an item
    $('select').on("select2:selecting", function(evt, f, g) {
      disableSel2Group(evt, this, true);
    });

    // Select2 Event handler for unselecting an item
    $('select').on("select2:unselecting", function(evt) {
      disableSel2Group(evt, this, false);
    });
  });


  // At some point during the select2 instantation it created the 
  // data object it needs with the source select option.
  // This function, called by the events above to set the current status for the
  // group for which the selected option belongs.
  function disableSel2Group(evt, target, disabled) {
    // Found a note in the Select2 formums on how to get the item to be selected

    var selId = evt.params.args.data.id;
    var group = $("option[value='" + selId + "']").attr("groupid");

    var aaList = $("option", target);
    $.each(aaList, function(idx, item) {
      var data = $(item).data("data");

      var itemGroupId = $("option[value='" + data.id + "']").attr("groupid");
      if (itemGroupId == group && data.id != selId) {
        data.disabled = disabled;
      }
    })
  }

Check demo here



MySQL Select query to validate email

MySQL supports another type of pattern matching operation based on the regular expressions, REGEXP operator used for pattern matching.


SELECT * FROM `users`,
WHERE `email` REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$';

And now for your question of tracking multiple tables, you can use comma seperated table names right?

SELECT * FROM `users`, `customers`, `clients`
         WHERE `email` NOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$';