Loading...
More PHP Posts
<?phpfunction getFileExtension($file) {return end(explode(".", $file));}?>
<?php$username = "Austin Leath -_#";$username_err = "no error";if(preg_match('/[^a-z_\-0-9]/i', $string)) {$username_err = "Username can only contain alphanumeric characters, dashes, and underscores.";}echo $username_err?>
<?php$array = array('fruit1' => 'apple','fruit2' => 'orange','fruit3' => 'grape','fruit4' => 'apple','fruit5' => 'apple');// this cycle echoes all associative array// key where value equals "apple"while ($fruit_name = current($array)) {if ($fruit_name == 'apple') {echo key($array), "\n";}next($array);}?>
<?php$listOfFiles = glob("*.{jpg,png,gif,tiff,jpeg}", GLOB_BRACE);echo 'images = []; ';for($x = 0; $x <= count($listOfFiles)-1; $x++) {echo "images[" . $x . "] =" . '"' . $listOfFiles[$x] . '"' . "; ";}?>
<?phpfunction uniqidReal($length = 8) {// uniqid gives 8 chars, can be changedif (function_exists("random_bytes")) {$bytes = random_bytes(ceil($length / 2));} elseif (function_exists("openssl_random_pseudo_bytes")) {$bytes = openssl_random_pseudo_bytes(ceil($length / 2));} else {throw new Exception("no cryptographically secure random function available");}return substr(bin2hex($bytes), 0, $length);}/*//for testingfor($i = 0; $i < 10; $i++) {echo "<br>";echo uniqidReal();}*/?>
<?php$im = imagecreatefrompng('example.png');$size = min(imagesx($im), imagesy($im));$im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);if ($im2 !== FALSE) {imagepng($im2, 'example-cropped.png');imagedestroy($im2);}imagedestroy($im);?>