[resolved] Output PHP problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

[resolved] Output PHP problem

Post by Noobie »

Hi all

I've got a randomising script like this:

Code: Select all

<?php
           $fc = join("",file("/whatever.txt"));
           $fc = "$fc\n"; $spl = split("\n",$fc);
           srand((double)microtime()*1000000);
           $rndnum = (rand()%(count($spl)-1));
           echo $spl[$rndnum];
?>
Which outputs the lines of a .txt file randomly.

This works beautifully when it's outputting HTML etc but I'm trying to get it to output some PHP instead but it's not working properly as the PHP tags and all is visible within the source of the final page.

(The end result is to randomise some adverts that are called using PHP from a WordPress plugin where a line in the .txt file would look like this:
<?php AdServe("boxad1"); ?><?php AdServe("boxad2"); ?><?php AdServe("boxad3"); ?><?php AdServe("boxad4"); ?><?php AdServe("boxad5"); ?>
The next line has the ads in a different order. The idea being that it should call a line, randomly, thus randomising the appearance of the ads)

How can I get this to output the PHP before it displays? Am I going about this completely the wrong way?
Last edited by Noobie on Tue Mar 04, 2008 5:37 am, edited 1 time in total.
Noobie
Forum Commoner
Posts: 85
Joined: Sun May 15, 2005 11:38 am

Re: Output PHP problem

Post by Noobie »

Typical - soon as I post the problem I manage to work it out!

Sorry!
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: [resolved] Output PHP problem

Post by kryles »

should post the solution for anyone else in the future with same type of issue though :|
Post Reply