Skip to content

Instantly share code, notes, and snippets.

@wett1988
Created November 24, 2016 10:28
Show Gist options
  • Save wett1988/f1a83b0b52ef0bd07abb1da12f420624 to your computer and use it in GitHub Desktop.
Save wett1988/f1a83b0b52ef0bd07abb1da12f420624 to your computer and use it in GitHub Desktop.
Detect if a string is a data URL (PHP, JS)
// For js more info in source: https://gist.github.com/bgrins/6194623
function isDataURL(s) {
return !!s.match(isDataURL.regex);
}
isDataURL.regex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
<?php
function isDataURL($s){
if ( preg_match(" /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i", $s) ){
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment