Micro utility functions for everyday PHP tasks. Minimal helpers for maximum flow
Minimal utility helpers for everyday PHP tasks (object-oriented version)
MicrofyClass.php is the object-oriented version of microfy.php
β a minimalist utility class packed with static helper methods to simplify everyday PHP development.
It brings the same no-bloat, no-dependency philosophy β now in a class-based format β offering tools for request handling, debugging, logging, HTML snippets, database access, and more.
Forget frameworks when all you need is power and speed β Microfy is your coding pocketknife.
isset($_GET['x']) ? $_GET['x'] : ''
Microfy::get()
, Microfy::pp()
, Microfy::dbAll()
right awayget()
, post()
, request()
and prefixed variantspp()
, pd()
, mpp()
, mlog()
, with optional returns (pdd()
, pdr()
)dbPdo()
, dbAll()
, dbExists()
, etc.h()
, br()
, codePhp()
, mark()
, a()
, b()
, ul()
, li()
and moregetArray()
(formerly getR()
) for safe key lookupsjsonf()
for simple flat-file configscList()
, cStr()
for smart numbered headings and countersUse MicrofyClass.php
when:
Want the simplicity of pp($data)
or dbAll(...)
in your OOP project?
Just include microfy_aliases.php to use short, procedural-style aliases for all Microfy:: methods β no need to prefix everything manually.
require_once 'MicrofyClass.php';
require_once 'microfy_aliases.php';
pp(['quick', 'debug']); // works alongside Microfy::pp(...)
// Set example input values
$_GET = [
'name' => 'Alice',
'city' => 'Wonderland'
];
$_POST = [
'age' => '30'
];
$name = get('name', 'Guest');
$age = post('age', 'unknown');
$city = request('city', 'Nowhere');
p("Hello, $name ($age), from $city.");
p("val($_GET, 'name', 'NoName'));
Hello, Alice (30), from Wonderland.
val($_GET, 'name'): Alice
pp([
'getVars' => getVars(['name', 'city']),
'postVars' => postVars(['age']),
'reqVars' => reqVars(['name', 'city', 'age'])
]);
Array ( [getVars] => Array ( [name] => Alice [city] => Wonderland ) [postVars] => Array ( [age] => 30 ) [reqVars] => Array ( [name] => [city] => [age] => ) )
injectGlobals(['name', 'city'], $_GET);
p("Injected Global: \$name = $name");
Injected Global: $name = Alice
extract(getVarsWithPrefix($_GET));
br($get_name);
br($$get_city);
$_POST['lang'] = 'en';
$_POST['theme'] = 'dark';
pp(loadInputs(['lang', 'theme'], $_POST));
Array ( [0] => en [1] => dark )
echo htmlTable(dbAll($pdo, "SELECT id, username FROM users"));
id | username |
---|---|
1 | admin |
2 | bob |
pp(dbOne($pdo, "SELECT * FROM users WHERE id = 1"));
p("Total users: " . dbVal($pdo, "SELECT COUNT(*) FROM users"));
p("User #1 exists? " . (dbExists($pdo, 'users', 'id', 1) ? 'Yes' : 'No'));
} catch (Exception $e) {
p("β οΈ DB Error: " . $e->getMessage());
}
Array ( [id] => 1 [0] => 1 [username] => admin [1] => admin )
Total users: 2
User #1 exists? Yes
h(2, 'π Pretty Debugging');
pp(['a' => 1, 'b' => [2, 3]]);
logPr(['user' => 'admin', 'ip' => '127.0.0.1']);
logVd(['server' => $_SERVER['SERVER_NAME'] ?? 'cli']);
Array ( [a] => 1 [b] => Array ( [0] => 2 [1] => 3 ) )
h(2, 'π§± HTML Helpers');
h(1, 'Heading');
echo b("Bold") . ' ' . i("Italic") . ' ' . bi("Bold+Italic");
p("Paragraph");
echo small("Note");
echo div("Inside div", ['class' => 'box']);
section("Sectioned");
ul(['One', 'Two', 'Three']);
ulOpen();
li("First");
li("Second");
ulClose();
br();
hr();
Paragraph
Note code("Simple string");
codephp('<?php echo "Hello"; ?>');
codejson(json_encode(['key' => 'value']));
codesql('SELECT * FROM table');
Simple string
<?php echo "Hello"; ?>
{"key":"value"}
SELECT * FROM table
echo "Now: " . now();
echo "ENV PATH: " . env('PATH', 'n/a') ;
echo "Slug: " . slugify("Hello World!") ;
echo "hsc(): ";
hsc('<b>XSS</b>');
hsc(): <b>XSS</b>echo cStr('Some Text');
echo cStr('Next');
1. Some Textpp(jsonArray(['status' => 'ok', 'user' => $name]));
pp(jsonString('All good!'));
pp(jsonString('Something went wrong.', false));
{ "status": "ok", "user": "Alice" }
{ "status": "ok", "msg": "All good!" }
{ "status": "fail", "msg": "Something went wrong." }
session_start();
$_SESSION['token'] = 'abc123';
debugSession();
Array ( [token] => abc123 )
Released under the MIT License β © 2024β2025
itnb.com
This project is not affiliated with or endorsed by the PHP Foundation.
Use at your own risk β no warranties, no guarantees, just useful code.