使用getTemplate拉随机php文件
问题描述:
I'm trying to pull a random add into a page. I can pull this
<? getTemplate('sideadd.php'); ?>
But if I want to pull sideadd1.php / sideadd2.php
randomly, I thought I would be able to do this.
<? getTemplate('sideadd '.rand(1,2).' .php'); ?>
But unfortunately I can't. it returns nothing.
So what's the best way of going about this. Pretty new to php so sorry if I dont explain myself very well.
答
Change:
<? getTemplate('sideadd '.rand(1,2).' .php'); ?>
to:
<? getTemplate('sideadd'.rand(1,2).'.php'); ?>
You were generating 'sideadd 1 .php', instead of 'sideadd1.php'