Monday, February 7, 2011

PHP dynamic file

Was busy with html5 recently, even though the security issue and lack of broswer support. Did not wrok on php stuff for a while. I created a website long time ago, the owner doesn't want to spend money and ask some no-brain guy to maitain the site and made a big mess.

The site has a testmonial side note to display some customer's profile (a few words and pictures), they want to dynamically display different customers' profile each time (refresh, entering page, etc). So it's very easy for PHP to set up that.

step 1: creating different files names as note1, 2, 3, .....
step 2: dynamically include those files like this:
<?php include 'includes/side'.$n.'.inc'; ?>
step 3: random generating the number using rand(begin_number, end_number)

Overall just like this: <?php $n=rand(1,9); include 'includes/side'.$n.'.inc'; ?>

pretty cool? PHP is the king :)

No comments:

Post a Comment