Skip to content

Instantly share code, notes, and snippets.

@octavian-nita
Last active August 29, 2015 13:56
Show Gist options
  • Save octavian-nita/8846781 to your computer and use it in GitHub Desktop.
Save octavian-nita/8846781 to your computer and use it in GitHub Desktop.
PHP tools
<?php
//! Encode all characters in every command line argument to their html entity equivalent:
//! (see http://stackoverflow.com/questions/3005116/how-to-convert-all-characters-to-their-html-entity-equivalent-using-php)
function toHtmlEntities($string)
{
$convMap = array(0x000000, 0x10ffff, 0, 0xffffff); // could be extracted...
return mb_encode_numericentity($string, $convMap, "UTF-8");
}
if ($argc > 1) {
$howMany = count($argv);
for ($i = 1; $i < $howMany; $i++) {
echo toHtmlEntities($argv[$i]), PHP_EOL;
}
}
//! Use Imagick to create a fixed size thumbnail by first scaling the image up or down and then
//! cropping a specified area from the center:
$tw = 185;
$th = 170;
$bn = 'false-blue';
$image = new Imagick($bn . '.jpg');
$image->cropThumbnailImage($tw, $th);
$image->writeImage($bn . ',small.jpg');
//! Output all arguments provided to a function:
function p()
{
foreach (func_get_args() as $arg) {
echo $arg . '<br />';
}
}
//! MOD operator:
function mod($dividend, $divisor)
{
$mod = $dividend % $divisor;
return $mod >= 0 ? $mod : $mod + abs($divisor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment