Skip to main content

preg_match() username sanitization

Nov 18, 2022AustinLeath
Loading...

More PHP Posts

Get Image Information

Nov 19, 2022CodeCatch

0 likes • 0 views

<?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];
}
?>

Make Random Number

Nov 19, 2022CodeCatch

0 likes • 0 views

<?php
function getRandomId($min = NULL, $max = NULL) {
if (is_numeric($min) && is_numeric($max)) {
return mt_rand($min, $max);
}
else {
return mt_rand();
}
}
?>

Get File Extension

Nov 19, 2022CodeCatch

0 likes • 1 view

<?php
function getFileExtension($file) {
return end(explode(".", $file));
}
?>

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

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

Ace Editor Languages

Nov 18, 2022AustinLeath

0 likes • 0 views

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