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
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);
        }
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.