0

Hai
I have some html files and i would like to display them in a random manner using the php.
can any one help me out..I have been trying this one..
but it is not working..

<?php
$dir="./clock/";
$nimg="10";
$itype="html";
$rnumb=rand(1,$nimg);

echo "<a href=".$dir."clock".$rnumb.".".$itype."></a>";
?>
2
Contributors
10
Replies
14
Views
7 Years
Discussion Span
Last Post by network18
0

Hai
I have some html files and i would like to display them in a random manner using the php.
can any one help me out..I have been trying this one..
but it is not working..

<?php
$dir="./clock/";
$nimg="10";
$itype="html";
$rnumb=rand(1,$nimg);

echo "<a href=".$dir."clock".$rnumb.".".$itype."></a>";
?>

I have modified your code -

//by speifying this and using in the echo below, all the files in the array should be from this directory only
$dir = "./clock/";
$arr_file_names = array(1=>'my_string.html','my_script.html','new_counntry.html','test.php','test1.php','test2.php','etst2.php','something.php','ejej.php','bored.php');

$number_of_html_files = count($arr_file_names);

$rnumb = ceil(rand(1,$number_of_html_files));
// test the file name with its file path here - 
//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb]."></a>";
?>
0

I have modified your code -

//by speifying this and using in the echo below, all the files in the array should be from this directory only
$dir = "./clock/";
$arr_file_names = array(1=>'my_string.html','my_script.html','new_counntry.html','test.php','test1.php','test2.php','etst2.php','something.php','ejej.php','bored.php');

$number_of_html_files = count($arr_file_names);

$rnumb = ceil(rand(1,$number_of_html_files));
// test the file name with its file path here - 
//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb]."></a>";
?>

hai pal
this is not displaying any thing..
i have the code changed to this one..
then it is just showing me the link. where as i require the code to display the html file directly

<?php
$dir = "./clock/";

$arr_file_names = array(1=>'clock1.html','clock2.html','clock3.html','clock4.html','clock5.html','clock6.html','clock7.html','clock8.html','clock9.html','clock10.html');

 

$number_of_html_files = count($arr_file_names);

 

$rnumb = ceil(rand(1,$number_of_html_files));

// test the file name with its file path here -

//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";

?>
0

hai pal
this is not displaying any thing..
i have the code changed to this one..
then it is just showing me the link. where as i require the code to display the html file directly

<?php
$dir = "./clock/";

$arr_file_names = array(1=>'clock1.html','clock2.html','clock3.html','clock4.html','clock5.html','clock6.html','clock7.html','clock8.html','clock9.html','clock10.html');

 

$number_of_html_files = count($arr_file_names);

 

$rnumb = ceil(rand(1,$number_of_html_files));

// test the file name with its file path here -

//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";

?>

That means you want to include the file randomly in the page (yes, its called 'include'), so need to use the anchor tags
replace the line10 in above code with the below one -

include(".$dir."clock".$arr_file_names[$rnumb].");
0

That means you want to include the file randomly in the page (yes, its called 'include'), so need to use the anchor tags
replace the line10 in above code with the below one -

include(".$dir."clock".$arr_file_names[$rnumb].");

hai
it is displaying this error

Parse error: parse error, unexpected T_STRING in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17

<?php
$dir = "./clock/";

$arr_file_names = array(1=>'1.html','2.html','3.html','4.html','5.html','6.html','7.html','8.html','9.html','10.html');

 

$number_of_html_files = count($arr_file_names);

 

$rnumb = ceil(rand(1,$number_of_html_files));

// test the file name with its file path here -

//echo $dir."clock".$arr_file_names[$rnumb];
include("$dir."clock".$arr_file_names[$rnumb]");
echo "<a href=".$dir."clock".$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";

?>
0

its right, line17 should have been like this -

include("$dir".clock."$arr_file_names[$rnumb]");

Thank you so much pal...
The issue is now resolved.....:icon_razz:

0

Thank you so much pal...
The issue is now resolved.....:icon_razz:

but the only thing is that it is displaying the path as http://localhost/
when i am checking in my machine..
how do i change it to my machine ip

an if i changed it to my ip address it dispalying a big error.

Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17

Warning: include(http://192.168.0.35/chaitu/magpierss/clock/clock9.html) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17

Warning: include() [function.include]: Failed opening 'http://192.168.0.35/chaitu/magpierss/clock/clock9.html' for inclusion (include_path='.;C:\Program Files\xampp\php\pear\') in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17


dir is chaned to

$dir = "http://192.168.0.35/chaitu/magpierss/clock/";

Edited by ym_chaitu: additional info

0

hai
silly me:$ i have done the wrong in the html files
it is displaying this error from that files..
Thank you for your help pal...

0

but the only thing is that it is displaying the path as http://localhost/
when i am checking in my machine..
how do i change it to my machine ip

an if i changed it to my ip address it dispalying a big error.

Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17

Warning: include(http://192.168.0.35/chaitu/magpierss/clock/clock9.html) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17

Warning: include() [function.include]: Failed opening 'http://192.168.0.35/chaitu/magpierss/clock/clock9.html' for inclusion (include_path='.;C:\Program Files\xampp\php\pear\') in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17


dir is chaned to

$dir = "http://192.168.0.35/chaitu/magpierss/clock/";

Its fine if you put the relative path, instead of the absolute one.
Its about how you define the $dir
make it this way -

$dir = "/clock/";

at line3
or else you can set it to the ip too, as below -

$dir = "http://192.168.0.35/chaitu/magpierss/clock/";
include("$dir".$arr_file_names[$rnumb]);
echo "<a href=".$dir.$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";

at line3

Edited by network18: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.