CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

For Your Consideration

| Comments

This was sent along anonymously, along with the question:

“Does this count as horror code or pure evil genius code?”

What say you, dear reader? I cut and paste, you decide.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

function cli_parsestr($string, $config, $mainconf, $options, $custom = array())
{
    if (empty($string)) {
        return '';
    }

    $replaces = array(
            'config' => '/%%$0%%/',
            'mainconf' => '/%\*$0\*%/',
            'options' => '/%&$0&%/',
            'custom' => '/%\\\$$0\\\$%/',
            );

    foreach ($replaces as $var => $replace) {
        if (!empty($$var) && is_array($$var)) {
            $string = preg_replace(preg_replace('/.+/', $replace, array_keys($$var)), array_values($$var), $string);
        }
    }
    return $string;
}

Comments