microfyPHP-lite

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 microfyPHP-lite

Use microfy.php when you:

βš™οΈ Usage

1. Basics

For HTML-related helpers, you can replace:
echo microfy_foo()
with
e_microfy_foo()
or use:
e(hsc("Hello"), br(), h(2, "Title"));
instead of
hsc("Hello");
echo br();
echo h(2, "Title");

2. Request Simulation

get_var(), get_all(), get_vars()

$path = get_var("path"); // default is ""
$lang = get_var("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_var("lang", "default"); echo $lang;
Result from URL /?lang=...
default

post_var(), post_all(), post_vars()

$path = post_var("path"); // default is ""
      $lang = post_var("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_var(), request_all(), request_vars()

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

3. Array Access

get_r()

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

Name: Alice
Age (fallback): unknown

4. 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.

5. 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

6. Slugify

slugify("Hello World! Clean URL");

Result: hello-world-clean-url

7. JSON File Read

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

)

8. UL List

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

9. html

Links: a()

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

build_html_table()

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


10. 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() + e_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() + build_html_table()

$all = db_all($pdo, "SELECT * FROM users");
build_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!

11. Heading Helpers

h()

h(2, "Some h2 Title");

Some h2 Title


12. Line Breaks and Spacing

br(), bra(), e_hr()

e_bra(i("Result:")); e_br("First line"); e_hr("Part A", "Part B");
Result:

First line
Part A
Part B

13. Styling Examples

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

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 Italic
e_mark('Highlighted'); e_small('Fine print');
MarkedFine print
e_mark(bi('Hello!'));
Hello!
p('This is a paragraph.', 'info-text');

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

14. Auto-incrementing Titles

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

Result:
1. First
2. Second

15. Lists

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

16. Code Output

e_code() with PHP

e_code($php_code, 'php');

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

e_codejs()

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

Result: (in browser console)

e_codejson()

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

Result: Rendered as JSON block

e_codesql()

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

e_codehtml()

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

e_span(now());
2025-08-02 13:50:17

πŸ“¦ Also Available as Object-Oriented Version

If you prefer a class-based approach, check out
πŸ‘‰ microfyPHP (OOP) β€” similar helper functions, accessible via Microfy::.

πŸ”’ License

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.