Forum Moderators: coopster

Message Too Old, No Replies

Calling html with php

         

Simone100

9:09 pm on Aug 30, 2007 (gmt 0)

10+ Year Member



Hello, here is a situation that is very unusual. I did a google to see if others have this problem and couldn't find anything. Does anyone know if php has a problem calling html when you specifically ask for an html page?

Here is what is happening. All the files in the $allfiles array below are appearing but one. The html page called test.html is not appearing or is any other page I put in that has an html extension. I can't figure out why. In the "if" values below if I switch html with another position, the same problem occurs. The html pages are not being pulled when all the others are. Due to the nature of our pages, I need to call the pages a similar way specifying which ones I need pulled. Can anyone spot why this would be happening? Please let me know, thank you very much.

<?php
ini_set('error_reporting', 8191);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
$maximum = 3;
$a = (isset($_COOKIE['e']) && intval($_COOKIE['e']) < $maximum)? intval($_COOKIE['e'])+1 : 1;
setcookie("e", $a, time()+60*60*24*180);
$currentfile = $a;
$allfiles = Array();
$allfiles[1] = "test.php";
$allfiles[2] = "test.txt";
$allfiles[3] = "test.html";
if (in_array(substr($allfiles[$currentfile], -3), array('html','txt','php')))
{$get_content = file_get_contents($allfiles[$currentfile]);
echo $get_content;}
?>

[1][edited by: Simone100 at 9:11 pm (utc) on Aug. 30, 2007]

eeek

9:41 pm on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe the -3?

eeek

9:43 pm on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



{$get_content = file_get_contents($allfiles[$currentfile]);
echo $get_content;}

If you replace file_get_contents with readfile you won't need to store the contents and you can drop the echo.

cmarshall

9:53 pm on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (in_array(substr($allfiles[$currentfile], -3), array('html','txt','php')))

Here's your problem: "html" is 4 characters. You are only testing 3.

This will work:

if (in_array(substr($allfiles[$currentfile], -3), array('tml','txt','php')))

You could also rename it "test.htm", and test for "htm".

Simone100

7:20 am on Aug 31, 2007 (gmt 0)

10+ Year Member



Ai, that was it cmarshall, thanks very much!

Are you still there eeek?
What do you mean file_get_contents stores contents. How does it store them? Please let me know, thanks a lot.

[edited by: Simone100 at 7:22 am (utc) on Aug. 31, 2007]