Micro utility functions for everyday PHP tasks. Minimal helpers for maximum flow
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::getVar(), Microfy::pp(), Microfy::dbAll() right awaygetVar(), postVar(), requestVar() 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(...)
Microfy::pp(['quick', 'debug']);
// Set example input values
$_GET = [
'name' => 'Alice',
'city' => 'Wonderland'
];
$_POST = [
'age' => '30'
];$name = getVar('name', 'Guest');
$age = postVar('age', 'unknown');
$city = requestVar('city', 'Nowhere');
e_p("Hello, $name ($age), from $city.");
e_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);
e_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, email FROM users"));| id | username | |
|---|---|---|
| 1 | admin | admin@example.com |
| 2 | bob | bob@example.com |
$data = ['username' => 'alice', 'email' => 'alice@example.com'];
$id = dbInsert($pdo, 'users', $data);
e_p("Inserted user ID: $id");Inserted user ID: 3
dbUpdate($pdo, 'users', ['email' => 'alice@newmail.com'], 'id = ?', [$id]);dbDelete($pdo, 'users', 'username = ?', ['bob']);echo htmlTable(dbAll($pdo, "SELECT id, username, email FROM users"));| id | username | |
|---|---|---|
| 1 | admin | admin@example.com |
| 3 | alice | alice@newmail.com |
e_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
)
)
e_h(2, 'π§± HTML Helpers');
e_h(1, 'Heading');
echo b("Bold") . ' ' . i("Italic") . ' ' . bi("Bold+Italic");
e_p("Paragraph");
echo small("Note");
echo div("Inside div", ['class' => 'box']);
section("Sectioned");
ul(['One', 'Two', 'Three']);
ulOpen();
li("First");
li("Second");
ulClose();
e_br();
hr();Paragraph
Notee_code("Simple string");
e_codephp('<?php echo "Hello"; ?>');
e_codejson(json_encode(['key' => 'value']));
e_codesql('SELECT * FROM table');Simple string<?php echo "Hello"; ?>{"key":"value"}SELECT * FROM tableecho "Now: " . now();echo "ENV PATH: " . env('PATH', 'n/a') ;echo "Slug: " . slugify("Hello World!") ;echo "hsc(): ";
hsc('<b>XSS</b>');hsc(): 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(); echo Microfy::html_div([
Microfy::html_h2('Welcome'),
Microfy::html_span('This is a subheading.', ['class' => 'sub'])],
['class' => 'someclass']);echo html_ul(['One', 'Two', 'Three'], ['class' => 'my-list']);
echo html_p('This is a paragraph.');
echo html_code('echo "Hello World";');This is a paragraph.
echo "Hello World";echo html_form(
html_label('Email:', ['for' => 'email']) .
html_input(['type' => 'email', 'id' => 'email', 'name' => 'email']) .
html_button('Send', ['type' => 'submit']),
['method' => 'post']
);echo $html = html_div([
html_h4('Hello h4),
html_br(),
html_img(['src' => 'https://picsum.photos/id/237/50/75', 'alt' => 'image'])
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.