Zero Padded Numbers
function getZeroPaddedNumber($value, $padding) {
return str_pad($value, $padding, "0", STR_PAD_LEFT);
}
Usage
echo getZeroPaddedNumber(123, 4);
// outputs "0123"
… function getZeroPaddedNumber($value, $padding) {
return str_pad($value, $padding, "0", STR_PAD_LEFT);
}
echo getZeroPaddedNumber(123, 4);
// outputs "0123"
… function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
return $contents;
}
$data = array(
… function concatenate($elements, $delimiter = ', ', $finalDelimiter = ' and ') {
$lastElement = array_pop($elements);
return join($delimiter, $elements) . $finalDelimiter . $lastElement;
}
$array = array('John', 'Mary', 'Ishmal');
echo concatenate($array);
// outputs "John, Mary and Ishmal"
Provide second parameter, …
👋 Hey there! We want to give you a heads up that the source code that accompanies this series is no longer available to download. We still think there are valuable bits of information to get from the series, but …
👋 Hey there! We want to give you a heads up that the source code that accompanies this series is no longer available to download. We still think there are valuable bits of information to get from the series, but …
👋 Hey there! We want to give you a heads up that the source code that accompanies this series is no longer available to download. We still think there are valuable bits of information to get from the series, but …
Say that 10 times fast =).
Find out if a single checkbox is checked or not, returns true or false:
$('#checkBox').attr('checked');
Find all checked checkboxes:
$('input[type=checkbox]:checked');
… I’m busy, you’re busy, we’re all busy trying to meet deadlines and get things done in this crazy web world. I love learning new technologies when I can, but I’m the first to admit that I reach for tools that …
Back in the sad ol’ days of the v1.0 API, everytime any site using it loaded the script, a database call was made to pull a fresh quote from the Quotes on Design archives. It worked, but it was slow …
Have something happen on a click event, but only once! Unbind the click handler after the element has been clicked once.
$('#my-selector').bind('click', function() {
$(this).unbind('click');
alert('Clicked and unbound!');
});
Also see Ben’s comment below for jQuery’s .one() function which is …
There is probably a good chance if you read this blog that you also know David Walsh. David and I hail from the same hometown (Madison, Wisconsin) and have been friends for years. We’ve worked on a few projects together …