microfy.php

Micro utility functions for everyday PHP tasks. Minimal helpers for maximum flow

🧰 What is it?

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.

πŸ’‘ Why use it?

✨ Features

πŸ“Œ When to Use microfy.php

Use microfy.php when you:

βš™οΈ Usage

1. Request Simulation

get(), get_all(), get_vars()

$path = get("path"); // default is "" 
$lang = get("lang", "default");  // explicit default
Result from URL /?path=...
$path=
$lang= default

extract(get_all([
  'get_path'  => ['path'],             // default is ''
  'get_file'  => ['f'],                // also allowed
  'emlFile'   => ['emlFile', 'default'] // explicit default
]));

$get_path =
$get_file =
$emlFile = default
extract(get_vars(['path', 'f', 'emlFile']));

$path =
$f =
$emlFile =
extract(get_vars(['path', 'f', 'emlFile'], 'get_'));

$get_path =
$get_f =
$get_emlFile =
$lang = get("lang", "default"); echo $lang;
Result from URL /?lang=...
default

post(), post_all(), post_vars()

$path = post("path"); // default is "" 
$lang = post("lang", "default");  // explicit default
Result from URL /?path=...
$path=
$lang= default
Result (POST only):
none

extract(post_all([
  'post_path'  => ['path'],             // default is ''
  'post_file'  => ['f'],                // also allowed
  'emlFile'   => ['emlFile', 'default'] // explicit default
]));
extract(post_vars(['path', 'f', 'emlFile']));

request(), request_all(), request_vars()

$id = request("id", "none"); echo $id;
Result (GET or POST):
none

2. Array Access

get_r()

$array = ['name' => 'Alice', 'email' => 'alice@example.com'];
pp($array);
Result:
Array
(
    [name] => Alice
    [email] => alice@example.com
)
echo get_r($array, "name");

Name: Alice
Age (fallback): unknown

3. Debug Helpers

Pretty Print with pp()

$array = ['fruit' => 'apple', 'color' => 'red'];
pp($array);

Result: Pretty-printed array using print_r() inside <pre> tags
Array
(
    [fruit] => apple
    [color] => red
)

Pretty Print and Die with ppd()

ppd($array);

Result: Same as pp(), but stops script after output.

Multiple Pretty Prints with mpp()

mpp('Label 1', $array1, $array2);

Result: Multiple print_r() values in <pre> blocks.

Var Dump with pd()

pd($array, 'Labeled Dump');

Result: var_dump with optional label, inside <pre> tags.
Labeled Dump:
array(2) {
  ["fruit"]=>
  string(5) "apple"
  ["color"]=>
  string(3) "red"
}

Var Dump and Die with pdd()

pdd($array, 'Dump + Die');

Result: Like pd(), but halts execution after dump.

Quick Multiple Dumps with d()

d('dump label', $array, $config);

Result: Multiple var_dumps with <pre> tags, one per argument.

Quick Multiple Dumps and Die with dd()

dd($user, $session);

Result: Multiple dumps and immediate exit.

4. Logging

Logging with log_pr()

$testArray = ['name' => 'Alice', 'age' => 30]; 
log_pr($testArray, 'User Data');

Result: Logs print_r result to debug_pr.log

Logging with log_vd()

log_vd($testArray, 'User Data Dump');

Result: Logs var_dump result to debug_vd.log

Manual Logging with mlog()

mlog("Something happened", "Note", "custom.log");

Result: Appends plain labeled string to custom.log

5. Slugify

slugify("Hello World! Clean URL");

Result: hello-world-clean-url

6. JSON File Read

$data = jsonf("demo_data.json");
Result:
Array
(
    [title] => Sample JSON
    [items] => Array
        (
            [0] => one
            [1] => two
            [2] => three
        )

)

7. UL List

ul(["One", "Two"], "my-list");
Result:

8. html

Links: a()

echo a('example.com');
// <a href="https://example.com">https://example.com</a>

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

echo a('example.com', 'Visit', '_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>

html_table()

html_table($array);
idusernameemail
1alicealice@example.com
2bobbob@example.com
3carolcarol@example.com


9. DB Connect

DB Example: Basic Query


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

DB Example: db_all() + ul()


$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);

DB Example: db_all() + html_table()

$all = db_all($pdo, "SELECT * FROM users");
html_table($all);
idusernameemail
1alicealice@example.com
2bobbob@example.com
3carolcarol@example.com

DB Example: db_exists()


$email = "someone@example.com";
if (db_exists($pdo, "users", "email", $email)) {
    echo "User exists!";
}
Result:
User exists!

10. Heading Helpers

h()

h(2, "Some h2 Title");

Result:

Some h2 Title


11. Line Breaks and Spacing

br(), bra(), hr()

bra(i("Result:")); br("First line"); hr("Part A", "Part B");
Result:

First line
Part A
Part B

12. Styling Examples

b(), i(), bi() mark(), small()

echo b('Bold text', 'highlight');
echo i('Italic text', 'italic-grey');
echo small('Note', 'dim');
echo mark('Hot!', 'warning');
echo bi('Bold + Italic', 'combo');
echo b('Bold'); echo i('Italic'); echo bi('Bold Italic');
Bold Italic Bold Italic
echo mark('Highlighted'); echo small('Fine print');
Marked Fine print
echo mark(bi('Hello!'));
Hello!
p('This is a paragraph.', 'info-text');

This is a paragraph.


span(mark(b('Inline Highlight')));
Inline Highlight
span(b('Inline Class'), 'myhighlight';
Inline Class
section(bi('Section title') . '<br>' . small('Details...'), 'section-box');
Section title
Details...

13. Auto-incrementing Titles

c_st('First')
c_st('Second')
c_st('Second')

Result:
1. First
2. Second

14. Lists

    c_list(['Step A', 'Step B', 'Step C']);
    c_list(['One', 'Two'], true); // resets numbering
1. Step A
2. Step B
3. Step C
1. One
2. Two

15. Code Output

code() with PHP

code($php_code, 'php');

Result:
<?php echo "Hello world!"; ?>

codejs()

const name = "Alice";
console.log("Hello " + name);

Result: (in browser console)

codejson()

{
  "name": "Alice",
  "email": "alice@example.com"
}

Result: Rendered as JSON block

codesql()

SELECT * FROM users WHERE email LIKE '%@example.com';

codehtml()

<div class="user">
  <strong>Alice</strong>
</div>

2025-06-20 09:27:25

πŸ”’ License

Released under the MIT License β€” © 2024–2025 MyAppz.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.