• Nov 19, 2022 •CodeCatch
0 likes • 0 views
<?php $json ='{"id":1,"name":"foo","interest":["wordpress","php"]}'; $obj=json_decode($json); echo $obj->interest[1]; //prints php ?>
<?php function getRandomId($min = NULL, $max = NULL) { if (is_numeric($min) && is_numeric($max)) { return mt_rand($min, $max); } else { return mt_rand(); } } ?>
<?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); ?>
<?php /* * @param string $file Filepath * @param string $query Needed information (0 = width, 1 = height, 2 = mime-type) * @return string Fileinfo */ function getImageinfo($file, $query) { if (!realpath($file)) { $file = $_SERVER["DOCUMENT_ROOT"] . $file; } $image = getimagesize($file); return $image[$query]; } ?>
• Nov 18, 2022 •AustinLeath
<?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 //generate 239 rgba colors for codecatch's 239 supported programming languages! //this was used to generate the colors that are used in the pie chart on https://codecatch.net/graphs.php function rgbagenerator() { $count = 239; for ($i=0; $i < $count; $i++) { echo "'rgba(". mt_rand(0,255) . ",". mt_rand(0,255) . ",". mt_rand(0,255) . ",1)',"; echo "<br>"; } } rgbagenerator(); ?>