k0a1a Posted April 19, 2008 Share Posted April 19, 2008 Hi there, I'm new to PHP, can you please give me an idea. My PHP application is a Web site developed by some 3rd party developer. Exact execution flow is not known to me, but approximately it goes like that: a home-made CMS written in PHP selects data from database and then calls HTML template. In this template special constructs like {val var="title_`$smarty.session.lang`"} get evaluated and replaced with their values. Then the whole HTML is returned to the client. It must have something to do with Smarty. Now the question. I need to assign a variable the value, which is a random number. I know how to assign a constant to a variable: {assign var=myVariable value="1"} So the "little" thing I'm missing is - how to assign it a result of mt_rand(0,1) instead of the constant 1? Thank you in advance! Link to comment https://forums.phpfreaks.com/topic/101924-call-a-function-in-html/ Share on other sites More sharing options...
p2grace Posted April 20, 2008 Share Posted April 20, 2008 Is it an actual php page? Could you put literal php code into the system? {assign var=myVariable value="<?php rand(); ?>"} Link to comment https://forums.phpfreaks.com/topic/101924-call-a-function-in-html/#findComment-521654 Share on other sites More sharing options...
k0a1a Posted April 20, 2008 Author Share Posted April 20, 2008 The value of the variable becomes then: <?php rand(); ?> It does not evaluate it but treats as a string. Same thing BTW with arithmetic expressions such as 3+2. Link to comment https://forums.phpfreaks.com/topic/101924-call-a-function-in-html/#findComment-521768 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 rand is a built-in class, that when you give it a low and high number, it will randomly choose a number between those 2 numbers, so to use it, you would enter {assign var=myVariable value="<?php print rand(1,5); ?>"} or whatever number range you want to use. Link to comment https://forums.phpfreaks.com/topic/101924-call-a-function-in-html/#findComment-521771 Share on other sites More sharing options...
k0a1a Posted April 20, 2008 Author Share Posted April 20, 2008 Thanks folks for the attempts! In fact, assign is documented here. Not sure if it's possible to achieve my goal with assign at all, I gave up experimenting pretty soon and implemented random number in that logic in CMS, which retrieves data from DB. Link to comment https://forums.phpfreaks.com/topic/101924-call-a-function-in-html/#findComment-522038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.