473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
Jul 17 '05 #1
4 1946
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 =--
Jul 17 '05 #2
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" <fr*********@hotmail.com> napisal w wiadomosci
news:2e**************************@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

Jul 17 '05 #3
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
Jul 17 '05 #4
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" <fr*********@hotmail.com> napisal w wiadomosci
news:2e**************************@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

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
50
by: sabarish | last post by:
Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
22
by: maxwell | last post by:
I'm having a problem using the XML "include" mechanism, which I think has to do with namespaces. I have an XML file that has a lot of repetition--a sequence of elements that appear multiple...
3
by: cyberco | last post by:
I must be overlooking something here... I'm trying to edit a line in a text file. I thought this was easy with fileinput, but all examples do not write the line back to the file but simply 'print'...
12
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works...
5
by: =?Utf-8?B?SmltbWVy?= | last post by:
Hello, I've been trying to create a WCF SOAP Router Service that can forward not just the message body but also any security headers set by the originator of the message. The destination service...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
13
by: Robert Cloud | last post by:
Is it possible to include assembly language routines in C if I'm using a compiler which has an assembler such as gcc? could I include them in a main function or would I have to write a seperate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.