"string" != "string"

Posted by Misiur on Stack Overflow See other posts from Stack Overflow or by Misiur
Published on 2010-05-23T15:11:41Z Indexed on 2010/05/23 15:20 UTC
Read the original article Hit count: 300

Filed under:
|
|
|

Hi.

I'm doing some kind of own templates system. I want to change

<title>{site('title')}</title>

Into function "site" execution with parameter "title". Here's

private function replaceFunc($subject)
{
    foreach($this->func as $t)
    {
        $args = explode(", ", preg_replace('/\{'.$t.'\(\'([a-zA-Z,]+)\'\)\}/', '$1', $subject));
        $subject = preg_replace('/\{'.$t.'\([a-zA-Z,\']+\)\}/', call_user_func_array($t, $args), $subject);
    }
    return $subject;
}

Here's site:

function site($what)
{
    global $db;
    $s = $db->askSingle("SELECT * FROM ".DB_PREFIX."config");

    switch($what)
    {
    case 'title':
        return 'Title of page';
        break;
    case 'version':
        return $s->version;
        break;
    case 'themeDir':
        return 'lolmao';
        break;
    default:
        return false;
    } 
}

I've tried to compare $what (which is for this case "title") with "title". MD5 are different. strcmp gives -1, "==", and "===" return false. What is wrong? ($what type is string. You can't change call_user_func_array into call_user_func, because later I'll be using multiple arguments)

© Stack Overflow or respective owner

Related posts about php

Related posts about regex