7-Views - Page 6 of 8 - Developers Blog
count(): Parameter must be an array or an object that implements Countable
count() throws a warning since PHP 7.2 in case a scalar or non-countable object is passed. We rely on this behavior in many places so code needs to be adjusted. More info https://wiki.php.net/rfc/counting_non_countables http://php.net/manual/en/function.count.php Here is my solution for this. function count_array($aArr) { if (is_array($aArr)) { return count($aArr); } else { return 0; } } […]
URIError: malformed URI sequence
The point is that if you use single % it breaks the logic of decodeURIComponent() function as it expects two-digit data-value followed right after it, for example, %20 (space). There is a solution to this. We need to check first if the decodeURIComponent() actually can run on given string and if not return the string as […]
Email Validation
function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@”]+(\.[^<>()\[\]\\.,;:\s@”]+)*)|(“.+”))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); }
How to check if a page is in an iFrame
function inIframe () { try { return window.self !== window.top; } catch (e) { return true; } }
List Files and Directories using glob in PHP
This function allows us to perform a search for path names using wildcards. which is similar to the rules used by common shells. Having the following parameters: $pattern (mandatory): The search pattern $flags (optional): One or more flags. GLOB_MARK – Adds a slash to each directory returned GLOB_NOSORT – Return files as they appear in the directory […]