Use token in php code on drupal site

10,126

Solution 1

I solved the problem by adding some token on the simplenews tokens. Thanks for your help anyway.

Solution 2

You could try the t() function like t('[token]').

But it seems that token_replace() is the function you like to use.

Share:
10,126
Sven
Author by

Sven

Updated on June 04, 2022

Comments

  • Sven
    Sven almost 2 years

    I am using some tokens in my drupal site.

    I have some php code where i need to use the token.

    print '[token]';
    

    This works perfect but i need to use it in a function like

    myfunctionname('[token]') {
    }
    

    This doesn't work. How can u use this token in php code without using the print function. I am trying to encode the string wit a special function. So i must use the value from that token as parameter in the function.

  • Sven
    Sven over 12 years
    I forgot to say that i tried the token_replace() function already. token_replace('simplenews-subscriber:mail'); also tried token_replace('[simplenews-subscriber:mail]');
  • Henrik Opel
    Henrik Opel over 12 years
    @SvenVdb: As long as it is not a global token, you need to pass the required 'base' data to token_replace() (I added the documentation link in the answer above).
  • nerdoc
    nerdoc about 8 years
    I have the same problem - this is not an answer to this question.