problem including file (intermediate)

This is a discussion on problem including file (intermediate) within the PHP Language forums, part of the PHP Programming Forums category; Hi, I wonder if someone can help me, I've set my web site up as follows: There is a '...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2004
FrobinRobin
 
Posts: n/a
Default problem including file (intermediate)

Hi,

I wonder if someone can help me, I've set my web site up as follows:
There is a 'services' page that displays .html pages in a sub-dir when
specified in the URL. I need use the switch function as the code
following shows:


<?php if(isset($_GET['p']))
{
switch ($_GET['p'])
{
// include ('test.inc');
case "test": include "./services/test.html"; break;
case "2test2": include "./services/2test2.html"; break;
default:
}
}
else
{
echo "<p><br><br><B>Please choose a topic from the left</B></p>\n";
}
?>

Basically.. I want to use the include(test.inc) file which contains
the two lines of code following it. But I get an error:

Parse error: parse error, expecting `T_CASE' or `T_DEFAULT' or `'}''
in /home/rmgraphics/public_html/services.php on line 27
- which is the include page line and I've commented out for now

I need to use the test.inc file for the case lines because I want to
manage the list by opening the file direct.

This is a bit over my head now.. I'm sure someone knows a good
workaround!

Thanks in advance

FrobinRobin
Reply With Quote
  #2 (permalink)  
Old 01-17-2004
Pedro Graca
 
Posts: n/a
Default Re: problem including file (intermediate)

FrobinRobin wrote:
> <?php if(isset($_GET['p']))
> {
> switch ($_GET['p'])
> {
> // include ('test.inc');
> case "test": include "./services/test.html"; break;

(snip)


You cannot have anything except "case ..." or "default ..." inside a
switch!

Try moving the switch to the included file

#v+
<?php
if (isset($_GET['p'])) {
include 'test.inc';
} else {
echo 'Choose from ...';
}
?>
#v-

and

#v+
<?php // test.inc
switch ($_GET['p']) {
case 'test': include './services/test.html'; break;
case '2test2': include './services/2test2.html'; break;
default:
}
?>
#v-
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Reply With Quote
  #3 (permalink)  
Old 01-17-2004
Chung Leong
 
Posts: n/a
Default Re: problem including file (intermediate)

Use an associative array instead:

test.php:
include("test.inc");
$path = @$topic_to_files[@$_GET['p']];
if($path) {
include($path);
}
else {
echo "<p><br><br><B>Please choose a topic from the left</B></p>\n";
}

test.inc:
$topic_to_files = array(
"page1" => "./services/page1.html",
"page2" => "./service/page2.html",
"page3" => "./service/page3.html"
);

Uzytkownik "FrobinRobin" <frobinrobin@hotmail.com> napisal w wiadomosci
news:2ecd35fd.0401161517.5625fb41@posting.google.c om...
> Hi,
>
> I wonder if someone can help me, I've set my web site up as follows:
> There is a 'services' page that displays .html pages in a sub-dir when
> specified in the URL. I need use the switch function as the code
> following shows:
>
>
> <?php if(isset($_GET['p']))
> {
> switch ($_GET['p'])
> {
> // include ('test.inc');
> case "test": include "./services/test.html"; break;
> case "2test2": include "./services/2test2.html"; break;
> default:
> }
> }
> else
> {
> echo "<p><br><br><B>Please choose a topic from the left</B></p>\n";
> }
> ?>
>
> Basically.. I want to use the include(test.inc) file which contains
> the two lines of code following it. But I get an error:
>
> Parse error: parse error, expecting `T_CASE' or `T_DEFAULT' or `'}''
> in /home/rmgraphics/public_html/services.php on line 27
> - which is the include page line and I've commented out for now
>
> I need to use the test.inc file for the case lines because I want to
> manage the list by opening the file direct.
>
> This is a bit over my head now.. I'm sure someone knows a good
> workaround!
>
> Thanks in advance
>
> FrobinRobin



Reply With Quote
  #4 (permalink)  
Old 01-17-2004
FrobinRobin
 
Posts: n/a
Default Re: problem including file (intermediate)

Thanks ... I worked out the switch problem this morning when I thought
... I'll just put that in there.. and it worked! I like what you said
chung - because when I upload a html page - the script also adds a new
line to the ./test.inc - I thought this was the best way to acheive
what I want?
A manageaable list of files as they get uploaded which can act as a
list to other pages to access? I usually use mysql but thought I'd try
it this way - good fun this PHP
Reply With Quote
  #5 (permalink)  
Old 01-17-2004
Chung Leong
 
Posts: n/a
Default Re: problem including file (intermediate)

And by the way, use readfile() instead of include(). Since the files are
HTML, there's no need for PHP to parse it.

You should seriously consider changing how you store the file list. Using
PHP to write PHP code is a bad idea for more than one reason.

Uzytkownik "FrobinRobin" <frobinrobin@hotmail.com> napisal w wiadomosci
news:2ecd35fd.0401170352.25c16f6e@posting.google.c om...
> Thanks ... I worked out the switch problem this morning when I thought
> .. I'll just put that in there.. and it worked! I like what you said
> chung - because when I upload a html page - the script also adds a new
> line to the ./test.inc - I thought this was the best way to acheive
> what I want?
> A manageaable list of files as they get uploaded which can act as a
> list to other pages to access? I usually use mysql but thought I'd try
> it this way - good fun this PHP



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0