Skip to main content

RGBA Generator

0 likes • Nov 18, 2022
PHP
Loading...
Download

More PHP Posts

Access Associative Array

AustinLeath
0 likes • Nov 18, 2022
PHP
<?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);
}
?>

Ace Editor Mode Getter

AustinLeath
0 likes • Nov 18, 2022
PHP
<?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

CodeCatch
0 likes • Nov 19, 2022
PHP
<?php
$json ='{"id":1,"name":"foo","interest":["wordpress","php"]}';
$obj=json_decode($json);
echo $obj->interest[1]; //prints php
?>

Make Random Number

CodeCatch
0 likes • Nov 19, 2022
PHP
<?php
function getRandomId($min = NULL, $max = NULL) {
if (is_numeric($min) && is_numeric($max)) {
return mt_rand($min, $max);
}
else {
return mt_rand();
}
}
?>

Search Function Display

AustinLeath
0 likes • Nov 18, 2022
PHP
<?php
session_start();
if(isset($_POST['search-submit'])) {
$currentFilter;
if(isset($_POST['search-filter']) && $_POST['search-filter'] == "search-all") {
$currentFilter = "All";
} else if(isset($_POST['search-filter']) && $_POST['search-filter'] == "search-by-title") {
$currentFilter = "Title";
} else if(isset($_POST['search-filter']) && $_POST['search-filter'] == "search-by-language") {
$currentFilter = "Language";
} else {
$currentFilter = "Username";
}
}
if(isset($_POST['search-submit']) && $_POST['search'] !== "") {
require_once 'includes/config.php';
$searchQuery = '%' . htmlspecialchars($_POST['search']) . '%';
$statement;
if(htmlspecialchars($_POST['search-filter']) == "search-all") {
$statement = $conn->prepare("SELECT * FROM user_posts WHERE privacy = 0 AND title LIKE ? OR username LIKE ? OR language LIKE ?");
$statement->bind_param("sss", $searchQuery, $searchQuery, $searchQuery);
} else if(htmlspecialchars($_POST['search-filter']) == "search-by-title") {
$statement = $conn->prepare("SELECT * FROM user_posts WHERE privacy = 0 AND title LIKE ?");
$statement->bind_param("s", $searchQuery);
} else if(htmlspecialchars($_POST['search-filter']) == "search-by-language") {
$statement = $conn->prepare("SELECT * FROM user_posts WHERE privacy = 0 AND language LIKE ?");
$statement->bind_param("s", $searchQuery);
} else {
$statement = $conn->prepare("SELECT * FROM user_posts WHERE privacy = 0 AND username LIKE ?");
$statement->bind_param("s", $searchQuery);
}
$statement->execute();
$result = $statement->get_result();
}
?>
<?php
if(isset($_POST['search-submit']) && $_POST['search'] !== "") {
if($result->num_rows > 0) {
$i = 1;
echo '<ul class="list-group mt-5">';
while($row = $result->fetch_assoc()) {
$linkName = "post.php?postID=" . $row['postID'];
$privacy = ($row['privacy'] == 0) ? "Public" : "Private";
if($privacy == "Public" || ($privacy == "Private" && (isset($_SESSION['username']) && ($row['username'] == $_SESSION["username"])))) {
echo '
<a class="post-box-link" href="' . $linkName . '">
<li class="list-group-item mb-2 border rounded post-box">
<h4><span style="color: #007bff;">' . $row['title'] . '</span> | ' . $row['language'] . '</h4>
<h5>' . $row['username'] . ' - ' . '<small>' . $row['uploadDate'] . '</small></h5>
</li>
</a>
';
$i++;
}
}
echo '</ul>';
}
}
?>

List Files in Directory

AustinLeath
0 likes • Nov 18, 2022
PHP
<?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] . '"' . "; ";
}
?>