What is so wrong with extract()?

I find that it is only bad practice in that it can lead to a number of variables which future maintainers (or yourself in a few weeks) have no idea where they’re coming from. Consider this scenario: extract($someArray); // could be $_POST or anything /* snip a dozen or more lines */ echo $someVariable; Where … Read more

Get min and max value in PHP Array

Option 1. First you map the array to get those numbers (and not the full details): $numbers = array_column($array, ‘weight’) Then you get the min and max: $min = min($numbers); $max = max($numbers); Option 2. (Only if you don’t have PHP 5.5 or better) The same as option 1, but to pluck the values, use … Read more

Extract the text out of HTML string using JavaScript

Create an element, store the HTML in it, and get its textContent: function extractContent(s) { var span = document.createElement(‘span’); span.innerHTML = s; return span.textContent || span.innerText; }; alert(extractContent(“<p>Hello</p><a href=”http://w3c.org”>W3C</a>”)); Here’s a version that allows you to have spaces between nodes, although you’d probably want that for block-level elements only: function extractContent(s, space) { var span= … Read more

Extract MSI from EXE

For InstallShield MSI based projects I have found the following to work: setup.exe /s /x /b”C:\FolderInWhichMSIWillBeExtracted” /v”/qn” This command will lead to an extracted MSI in a directory you can freely specify and a silently failed uninstall of the product. The command line basically tells the setup.exe to attempt to uninstall the product (/x) and … Read more

How to extract top-level domain name (TLD) from URL

Here’s a great python module someone wrote to solve this problem after seeing this question: https://github.com/john-kurkowski/tldextract The module looks up TLDs in the Public Suffix List, mantained by Mozilla volunteers Quote: tldextract on the other hand knows what all gTLDs [Generic Top-Level Domains] and ccTLDs [Country Code Top-Level Domains] look like by looking up the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)