Useful Snippets

Welcome!


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at Unwanted.cloud

RSS Latest posts from my personal blog


Subscribe to RSS feed


Using PHP code in Invision Power Board templates

Stanislav KhromovStanislav Khromov

Invision Power Board gives you a PHP template tag. With this you can use PHP inside most templates (skin/block/page templates and more!).

Here’s a quick example of usage inside a template:

<php>
$foo = 5+5;
</php>

Print example 1 - {$foo}
Print example 2 - {parse expression="$foo"}

Both of the last two lines print our variable $foo. What’s interesting with the second example is that it can be used to evaluate a PHP expression.

For example, I had issues with an ISO-8859-1 RSS feed – to display it correctly, I ran it through utf8_decode(), as you can see in the example below:

{parse expression="utf8_decode($r['title'])"}

More reading
IPB Documentation on parse tags

Full-stack impostor syndrome sufferer & Software Engineer at Schibsted Media Group

Comments 2
  • Vladislav
    Posted on

    Vladislav Vladislav

    Reply Author

    Stanislav, thank you! I just had a problem with the output variables from the script.


  • Paul
    Posted on

    Paul Paul

    Reply Author

    Your information is deprecated. php-tag doesn’t work on the modern IPB versions. As for me, I used the PHP-code in IPB 4.1.12.2 with the following construction:


    {{$cur_year = date('Y');}}
    {$cur_year}