php variable in HTML-Block

Re: php variable in HTML-Block

by Gordon Bateson -
Number of replies: 0
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

> this obviously means that I have to build an HTML Block by myself, right?

Yes. I suggest you start with a copy of the HTML block and modify it so that it outputs exactly what you want.

You can then make it more general, so that does a search-and-replace, using PHP's "str_replace" function, for some special strings that you insert like "%%username%%" or "%%date%%". These strings can be any syntax you like, and can mean any thing you choose.

Finally, you can try using PHP's "preg_replace" function to extract all the PHP code, "<?php ... ?>", in the block content, and then use the "eval" function to convert that some output and send it to the browser. To be safe, you should limit the PHP functions that you allow in the block.

Please make sure you only allow admins to create content for you new block though! It could be fatal for your server, if it was used to allow untrusted users to run any PHP they liked.

all the best
Gordon