Jump to content

call a script using a single command


saltedm8

Recommended Posts

I am just learning php but I have messed with phpbb in the past and also one or 2 cms systems, ..

 

I have seen this << my_command >> and also this { my_command } being used to call a script into a template so for example if I typed in { CALL_MENU } then the script will get the menu script

 

I was wondering if anyone has any idea how this is done, Im not doing it for any project but it has just got me curious.. if you could give me a simple understandable explanation, I would love to see it

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/173222-call-a-script-using-a-single-command/
Share on other sites

They use something like preg_match Once they have all matches they look if it is one of the possible resources (function, ..). If it is they replace it with the output of the resource.

 

$matches = array();
if (preg_match('/{([A-Z-_]+)}/i', $str, $matches)) {
    foreach ($matches as $match) {
        $functionName = strtolower(trim($match, '{}'));
        if (function_exists($functionName)) {
            $output = call_user_func($functionName);
            $str = str_replace($match, $output, $str);
        }
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.