Skip to main content

Make Random Number

Nov 19, 2022CodeCatch
Loading...

More PHP Posts

Ace Editor Mode Getter

Nov 18, 2022AustinLeath

0 likes • 0 views

<?php
function modegetter($language) {
switch ($language) {
case 'ABC':
echo "abc";
break;
case 'ActionScript':
echo "actionscript";
break;
case 'ADA':
echo "ada";
break;
case 'Alda':
echo "alda";
break;
case 'Apache Conf':
echo "apache_conf";
break;
case 'Apex':
echo "apex";
break;
case 'AQL':
echo "aql";
break;
case 'AsciiDoc':
echo "asciidoc";
break;
case 'ASL':
echo "asl";
break;
case 'Assembly x86':
echo "assembly_x86";
break;
case 'AutoHotkey / AutoIt':
echo "autohotkey";
break;
case 'BatchFile':
echo "batchfile";
break;
case 'C':
echo "c_cpp";
break;
case 'C++':
echo "c_cpp";
break;
case 'C9Search':
echo "c9search";
break;
case 'Cirru':
echo "cirru";
break;
case 'Clojure':
echo "clojure";
break;
case 'Cobol':
echo "cobol";
break;
case 'CoffeeScript':
echo "coffee";
break;
case 'ColdFusion':
echo "coldfusion";
break;
case 'Crystal':
echo "crystal";
break;
case 'C#':
echo "csharp";
break;
case 'Csound Document':
echo "csound_document";
break;
case 'Csound':
echo "csound_orchestra";
break;
case 'Csound Score':
echo "csound_score";
break;
case 'CSS':
echo "css";
break;
case 'Curly':
echo "curly";
break;
case 'D':
echo "d";
break;
case 'Dart':
echo "dart";
break;
case 'Diff':
echo "diff";
break;
case 'Dockerfile':
echo "dockerfile";
break;
case 'Dot':
echo "dot";
break;
case 'Drools':
echo "drools";
break;
case 'Edifact':
echo "edifact";
break;
case 'Eiffel':
echo "eiffel";
break;
case 'EJS':
echo "ejs";
break;
case 'Elixir':
echo "elixir";
break;
case 'Elm':
echo "elm";
break;
case 'Erlang':
echo "erlang";
break;
case 'Forth':
echo "forth";
break;
case 'Fortran':
echo "fortran";
break;
case 'FSharp':
echo "fsharp";
break;
case 'FSL':
echo "fsl";
break;
case 'FreeMarker':
echo "ftl";
break;
case 'Gcode':
echo "gcode";
break;
case 'Gherkin':
echo "gherkin";
break;
case 'Gitignore':
echo "gitignore";
break;
case 'Glsl':
echo "glsl";
break;
case 'Gobstones':
echo "gobstones";
break;
case 'Go':
echo "golang";
break;
case 'GraphQLSchema':
echo "graphqlschema";
break;
case 'Groovy':
echo "groovy";
break;
case 'HAML':
echo "haml";
break;
case 'Handlebars':
echo "handlebars";
break;
case 'Haskell':
echo "haskell";
break;
case 'Haskell Cabal':
echo "haskell_cabal";
break;
case 'haXe':
echo "haxe";
break;
case 'Hjson':
echo "hjson";
break;
case 'HTML':
echo "html";
break;
case 'HTML (Elixir)':
echo "html_elixir";
break;
case 'HTML (Ruby)':
echo "html_ruby";
break;
case 'INI':
echo "ini";
break;
case 'Io':
echo "io";
break;
case 'Jack':
echo "jack";
break;
case 'Jade':
echo "jade";
break;
case 'Java':
echo "java";
break;
case 'JavaScript':
echo "javascript";
break;
case 'JSON':
echo "json";
break;
case 'JSON5':
echo "json5";
break;
case 'JSONiq':
echo "jsoniq";
break;
case 'JSP':
echo "jsp";
break;
case 'JSSM':
echo "jssm";
break;
case 'JSX':
echo "jsx";
break;
case 'Julia':
echo "julia";
break;
case 'Kotlin':
echo "kotlin";
break;
case 'LaTeX':
echo "latex";
break;
case 'Latte':
echo "latte";
break;
case 'LESS':
echo "less";
break;
case 'Liquid':
echo "liquid";
break;
case 'Lisp':
echo "lisp";
break;
case 'LiveScript':
echo "livescript";
break;
case 'LogiQL':
echo "logiql";
break;
case 'LSL':
echo "lsl";
break;
case 'Lua':
echo "lua";
break;
case 'LuaPage':
echo "luapage";
break;
case 'Lucene':
echo "lucene";
break;
case 'Makefile':
echo "makefile";
break;
case 'Markdown':
echo "markdown";
break;
case 'Mask':
echo "mask";
break;
case 'MATLAB':
echo "matlab";
break;
case 'Maze':
echo "maze";
break;
case 'MediaWiki':
echo "mediawiki";
break;
case 'MEL':
echo "mel";
break;
case 'MIPS':
echo "mips";
break;
case 'MIXAL':
echo "mixal";
break;
case 'MUSHCode':
echo "mushcode";
break;
case 'MySQL':
echo "mysql";
break;
case 'Nginx':
echo "nginx";
break;
case 'Nim':
echo "nim";
break;
case 'Nix':
echo "nix";
break;
case 'NSIS':
echo "nsis";
break;
case 'Nunjucks':
echo "nunjucks";
break;
case 'Objective-C':
echo "objectivec";
break;
case 'OCaml':
echo "ocaml";
break;
case 'Pascal':
echo "pascal";
break;
case 'Perl':
echo "perl";
break;
case 'pgSQL':
echo "pgsql";
break;
case 'PHP':
echo "php";
break;
case 'PHP (Blade Template':
echo "php_laravel_blade";
break;
case 'Pig':
echo "pig";
break;
case 'Powershell':
echo "powershell";
break;
case 'Praat':
echo "praat";
break;
case 'Prisma':
echo "prisma";
break;
case 'Prolog':
echo "prolog";
break;
case 'Properties':
echo "properties";
break;
case 'Protobuf':
echo "protobuf";
break;
case 'Puppet':
echo "puppet";
break;
case 'Python':
echo "python";
break;
case 'QML':
echo "qml";
break;
case 'R':
echo "r";
break;
case 'Raku':
echo "raku";
break;
case 'Razor':
echo "razor";
break;
case 'RDoc':
echo "rdoc";
break;
case 'Red':
echo "red";
break;
case 'RHTML':
echo "rhtml";
break;
case 'RST':
echo "rst";
break;
case 'Ruby':
echo "ruby";
break;
case 'Rust':
echo "rust";
break;
case 'SASS':
echo "sass";
break;
case 'SCAD':
echo "scad";
break;
case 'Scala':
echo "scala";
break;
case 'Scheme':
echo "scheme";
break;
case 'SCSS':
echo "scss";
break;
case 'Bash':
echo "sh";
break;
case 'SJS':
echo "sjs";
break;
case 'Slim':
echo "slim";
break;
case 'Smarty':
echo "smarty";
break;
case 'Smithy':
echo "smithy";
break;
case 'Snippets':
echo "snippets";
break;
case 'Soy Template':
echo "soy_template";
break;
case 'Space':
echo "space";
break;
case 'SQL':
echo "sql";
break;
case 'SQLServer':
echo "sqlserver";
break;
case 'Stylus':
echo "stylus";
break;
case 'SVG':
echo "svg";
break;
case 'Swift':
echo "swift";
break;
case 'Tcl':
echo "tcl";
break;
case 'Terraform':
echo "terraform";
break;
case 'Tex':
echo "tex";
break;
case 'Text':
echo "text";
break;
case 'Textile':
echo "textile";
break;
case 'Toml':
echo "toml";
break;
case 'TSX':
echo "tsx";
break;
case 'Twig':
echo "twig";
break;
case 'Typescript':
echo "typescript";
break;
case 'Vala':
echo "vala";
break;
case 'VBScript':
echo "vbscript";
break;
case 'Velocity':
echo "velocity";
break;
case 'Verilog':
echo "verilog";
break;
case 'VHDL':
echo "vhdl";
break;
case 'Visualforce':
echo "visualforce";
break;
case 'Wollok':
echo "wollok";
break;
case 'XML':
echo "xml";
break;
case 'XQuery':
echo "xquery";
break;
case 'YAML':
echo "yaml";
break;
case 'Zeek':
echo "zeek";
break;
case 'Django':
echo "django";
break;
default:
echo "text";
break;
}
}
?>

Generate 64K edges

Nov 18, 2022AustinLeath

0 likes • 4 views

<?php
header('Content-Type:text/html');
$jsonData = json_decode(file_get_contents("names.json"));
$namesArray = array();
foreach($jsonData as $data) {
$namesArray[] = $data;
}
for($i = 0; $i < 64000; $i++) {
echo 'D.add_edge("'. $namesArray[array_rand($namesArray)] . '", "' . $namesArray[array_rand($namesArray)]. '")';
echo "<br>";
}
?>

Crop an image

Nov 19, 2022CodeCatch

0 likes • 0 views

<?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);
?>

RGBA Generator

Nov 18, 2022AustinLeath

0 likes • 0 views

<?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();
?>

Parse JSON

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
$json ='{"id":1,"name":"foo","interest":["wordpress","php"]}';
$obj=json_decode($json);
echo $obj->interest[1]; //prints php
?>

ID Generator

Nov 18, 2022AustinLeath

0 likes • 0 views

<?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();
}
*/
?>