Reply
Need help with php
Old 02-23-2005, 01:56 PM Need help with php
Experienced Talker

Posts: 38
Hello,
I am a total noob in php, I just started learning 3 days ago :P

I am trying to get the "statement switching" function thingy right but Im getting parsing errors.

Here's the code:
Code:
<?php

// in order to change a function name, function a() to function page1(), you
// will have to go down to the switch function and change the cases to match the 
// function. So, case 'a': a(); would become case 'page1': page1();.  If you don't
// do this, it won't work properly.

function default(){
echo "i am the default page";
}

function a(){

//your page code, perhaps an include of your index.html file?

echo "I am function a";
echo "I'm activated when the browser url is index.php?act=a";

}

function b(){

//your page code, perhaps an include of your index.html file

echo "I am function b";
echo "I'm activated when the browser url is index.php?act=b";

}

switch($_GET['act']){

// change these in order to change the function name above.

   case 'a':
      a();
      break;
   case 'b':
      b();
      break;
   default:
	default();

}
?>
and here's the error is get:
Code:
Parse error: parse error, expecting `T_STRING' in C:\www\index.php on line 8
line 8 is function default(){, what's wrong with it?

Thanks in advance,
Azad

Last edited by eDevil : 02-23-2005 at 01:59 PM.
eDevil is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 02-23-2005, 02:22 PM
Skilled Talker

Posts: 62
After some testing, for some reason you cannot name a function default.

Therefore, just change the name to something else and everything else works.
(also dont forget to change the name of the function in your switch statement).
The Jasong is offline
Reply With Quote
View Public Profile
 
Old 02-23-2005, 03:06 PM
Extreme Talker

Posts: 160
'default' is a reserved word - it has a special significance to the language, namely its use in switch statements.
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 02-23-2005, 09:29 PM
Experienced Talker

Posts: 40
You have been particularly awkward with your approach in my opinion.

I would have named functions witha pre-definde prefix say "sec_". Then from there used an ereg expression on your section to make sure its only A-Z a-z 0-9 being entered, further then using a function_exists to see if there was a function for that section, if not then execute the default, or another of your choice. Then determining the value is safe, and the function exists use an eval statement to call the function. This way you dont have to continually ammend your case, and its pretty customisable...

If need be, i can code the above suggestions to show you...

Just a thought,

Dan

Last edited by iFuse : 02-23-2005 at 09:34 PM.
iFuse is offline
Reply With Quote
View Public Profile
 
Old 02-23-2005, 09:49 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
iFuse,

This is not a thread to highlight your knowledge, bud. This guy has said he is a beginner -

Quote:
Hello,
I am a total noob in php, I just started learning 3 days ago :P
The way you are going on, in 5 days he should be ready to take on nuclear physics!

Try and remember when you first started out in this language, or any other for that matter!

Steve.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 02-23-2005, 09:54 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
As to the question at hand.

You can use default, but it is unwise to do so. I suspect you are using a pre-made script that you found on the web. The 'default' should be changed to something else, something you can relate to. If you insist on using 'default', then change it to 'default_1' and it should work.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 02-24-2005, 12:32 AM
Experienced Talker

Posts: 38
I have changes it to 'index_default' and now it works. I have started using prefixes according to Dan.

And Steve, you are right, I have been following a tutorial from the web. It told me to put in any name i want for the function. Since it was the default function, i put in the word 'default', without knowing that it cannot be used.

Thanks a lot guys. I really appreciate your efforts to help.
eDevil is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need help with php
 

Thread Tools

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13834 seconds with 12 queries