Micro utility functions for everyday PHP tasks. Minimal helpers for maximum flow
microfy.php
is a lightweight collection of procedural PHP helper functions designed to speed up development and simplify common patterns like superglobal access, debugging, logging, array handling, UI snippets, and database access.
Forget bloated frameworks β microfy.php
gives you practical tools with no setup, no classes, no magic.
$_GET
, $_POST
, debug dumps, and simple logs.get_var()
, post_var()
, request_var()
, plus extract helperspp()
, pd()
, d()
, log_pr()
, log_vd()
, mlog()
jsonf()
for quick file-based config/datah()
, br()
, hr()
, mark()
, code()
, a()
, etc.get_r()
for safe accessdb_pdo()
, db_all()
, db_exists()
β simple and safec_str()
, e_clist()
for numbered docs or stepsUse microfy.php
when you:
echo microfy_foo()
withe_microfy_foo()
or use:e(hsc("Hello"), br(), h(2, "Title"));
instead ofhsc("Hello");
echo br();
echo h(2, "Title");
$path = get_var("path"); // default is ""
$lang = get_var("lang", "default"); // explicit default
Result from URL /?path=...extract(get_all([
'get_path' => ['path'], // default is ''
'get_file' => ['f'], // also allowed
'emlFile' => ['emlFile', 'default'] // explicit default
]));
extract(get_vars(['path', 'f', 'emlFile']));
extract(get_vars(['path', 'f', 'emlFile'], 'get_'));
$lang = get_var("lang", "default"); echo $lang;
Result from URL /?lang=...$path = post_var("path"); // default is ""
$lang = post_var("lang", "default"); // explicit default
Result from URL /?path=...extract(post_all([
'post_path' => ['path'], // default is ''
'post_file' => ['f'], // also allowed
'emlFile' => ['emlFile', 'default'] // explicit default
]));
extract(post_vars(['path', 'f', 'emlFile']));
$id = request_var("id", "none"); echo $id;
Result (GET or POST):$array = ['name' => 'Alice', 'email' => 'alice@example.com'];
pp($array);
Result:Array ( [name] => Alice [email] => alice@example.com )
e_get_r($array, "name");
$array = ['fruit' => 'apple', 'color' => 'red'];
pp($array);
Array ( [fruit] => apple [color] => red )
ppd($array);
mpp('Label 1', $array1, $array2);
pd($array, 'Labeled Dump');
Labeled Dump: array(2) { ["fruit"]=> string(5) "apple" ["color"]=> string(3) "red" }
pdd($array, 'Dump + Die');
d('dump label', $array, $config);
dd($user, $session);
$testArray = ['name' => 'Alice', 'age' => 30];
log_pr($testArray, 'User Data');
log_vd($testArray, 'User Data Dump');
mlog("Something happened", "Note", "custom.log");
slugify("Hello World! Clean URL");
$data = jsonf("demo_data.json");
Result:Array ( [title] => Sample JSON [items] => Array ( [0] => one [1] => two [2] => three ) )
e_ul(["One", "Two"], "my-list");
Result:echo a('example.com');
// <a href="https://example.com">https://example.com</a>
e_a('example.com', 'Visit');
// <a href="https://example.com">Visit</a>
echo a('example.com', 'Visit', '_blank');
// <a href="https://example.com" target="_blank">Visit</a>
e_a('example.com', 'Link', '_blank', 'btn btn-primary');
// <a href="https://example.com" target="_blank" class="btn btn-primary">Visit</a>
span('Visit our ' . a('docs.example.com', 'documentation'));
// <span>Visit our <a href="https://docs.example.com">documentation</a></span>
Linkecho build_html_table($array);
id | username | |
---|---|---|
1 | alice | alice@example.com |
2 | bob | bob@example.com |
3 | carol | carol@example.com |
$pdo = db_pdo("localhost", "your_db", "your_user", "your_pass");
$stmt = $pdo->query("SELECT * FROM users");
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
pp($data);
foreach ($data as $row) {
echo $row["id"] . " | ";
}
Array ( [0] => Array ( [id] => 1 [username] => alice ) [1] => Array ( [id] => 2 [username] => bob ) )1 | 2 |
$all = db_all($pdo, "SELECT * FROM users");
$usernames = array_column($all, "username");
ul($usernames);
$all = db_all($pdo, "SELECT * FROM users");
// Format each row as a string
$items = array_map(function ($row) {
return "{$row['id']}, {$row['username']}, {$row['email']}";
}, $all);
// Output as unordered list
ul($items);
$all = db_all($pdo, "SELECT * FROM users");
build_html_table($all);
id | username | |
---|---|---|
1 | alice | alice@example.com |
2 | bob | bob@example.com |
3 | carol | carol@example.com |
$email = "someone@example.com";
if (db_exists($pdo, "users", "email", $email)) {
echo "User exists!";
}
Result:h(2, "Some h2 Title");
e_bra(i("Result:")); e_br("First line"); e_hr("Part A", "Part B");
Result:e_b('Bold text', 'highlight');
e_i('Italic text', 'italic-grey');
e_small('Note', 'dim');
e_mark('Hot!', 'warning');
e_bi('Bold + Italic', 'combo');
e b('Bold'); e i('Italic'); echo bi('Bold Italic');
BoldItalicBold Italice_mark('Highlighted'); e_small('Fine print');
MarkedFine printe_mark(bi('Hello!'));
Hello!p('This is a paragraph.', 'info-text');
span(mark(b('Inline Highlight')));
Inline Highlightspan(b('Inline Class'), 'myhighlight';
Inline Classe_section(bi('Section title') . '<br>' . small('Details...'), 'section-box');
c_st('First')
c_st('Second')
c_st('Second')
e_clist(['Step A', 'Step B', 'Step C']);
e_clist(['One', 'Two'], true); // resets numbering
1. Step Ae_code($php_code, 'php');
<?php echo "Hello world!"; ?>
const name = "Alice";
console.log("Hello " + name);
{
"name": "Alice",
"email": "alice@example.com"
}
SELECT * FROM users WHERE email LIKE '%@example.com';
<div class="user">
<strong>Alice</strong>
</div>
e_span(now());
2025-08-02 13:50:17If you prefer a class-based approach, check out
π microfyPHP
(OOP) β similar helper functions, accessible via Microfy::
.
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.