• Nov 19, 2022 •CodeCatch
0 likes • 2 views
<?php function getFileExtension($file) { return end(explode(".", $file)); } ?>
0 likes • 0 views
<?php $json ='{"id":1,"name":"foo","interest":["wordpress","php"]}'; $obj=json_decode($json); echo $obj->interest[1]; //prints php ?>
• Nov 18, 2022 •AustinLeath
0 likes • 1 view
<?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] . '"' . "; "; } ?>
<?php function uniqidReal($length = 8) { // uniqid gives 8 chars, can be changed if (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 testing for($i = 0; $i < 10; $i++) { echo "<br>"; echo uniqidReal(); } */ ?>
<?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(); ?>
<?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); } ?>