Publishing System Settings Logout Login Register
PHP Random Content or Advertisment
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on August 16th, 2008
6159 views
PHP Coding
In this tutorial, I will show you how show random content or you could use this tutorial show random advertisement.
The Full PHP Code

<?php


$fcontents = join ('', file ('somefile.txt'));


$s_con = split("~",$fcontents);


$banner_no = (rand()%(count($s_con)-0));

echo $s_con[$banner_no];


?>


PHP code explaination

The First Part:
The First part of the code will get the file.

<?php
//opening the text file, if this line gives you error when compiling
//then you need to chmod 755 your text file

$fcontents = join ('', file ('somefile.txt'));



The Second Part:
This part will split the content by ~


//Spliting contents of file by looking for ~ mark between contents
//and storing everything into an array.
$s_con = split("~",$fcontents);


The Last Part:



//getting a random number which will be within the limit of the
//contents of the file, means if 5 different banners/ads/contents then the number
//will be between 0-4 (total 5 )
$banner_no = (rand()%(count($s_con)-0));

//simple echo the content
echo $s_con[$banner_no];


In the .TXT File


Your First Code or Content
~ <<< Make Sure to add this after each code or content
Your Second Code or Content



To show the content in your page, just include the .php file which has the code above within.

<?php include('path to your php file'); ?>

Enjoy!

[MY_P2L_AD]
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
AFG89

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top