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)
Edit:
Strlen $what - strlen title 403 - 5 Heh - looks like I haven't cut the rest ;)
var_dump
string(403) " title"