Jul 26, 2008

Question On The "p=pageid" Syntax

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Question On The "p=pageid" Syntax

Imtay22
OK, i have some code for the "p=pagied" php syntax.

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>
<a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br>
<?php
$page=$_GET['p'];
switch($page){
default:
echo 'This is the default page';
break;
case 'pagetwo':
echo 'This is page two';
break;
case 'pagethree':
echo 'This is page three<br>Cool, huh?';
}
?>
</body>
</html>


I have 10 lines of text i would like to put here-
CODE
case 'pagethree':
echo 'This is page three<br>Cool, huh?';


When I try to do that, I get the error-
QUOTE
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/imtay22/public_html/runescape/news.php on line 16

And this is line 16-
CODE
Avast, ye landlubbers! Murphy at Port Khazard has discovered a new spot teeming with fish for his trawler! He can't haul in this bountiful booty by his lonesome, though. With more high-quality fishy things to catch (those with the ability to catch manta rays and turtles, for example, are likely to catch quite a few more on the trawler than they could previously), it's time to strap on your Fishing gear, fix those leaks and start reaping the rewards.<br />Bring your friends along for a voyage on the high seas, but don't be afraid to get wet! The more friends that set sail, the greater the chance of more fish. Murphy has also fashioned himself a handy bank deposit box to allow you to send your fish straight to your bank (assuming you have the space, of course)!<br />RuneScape's Group of Advanced Gardeners (G.A.G.) recently commissioned the Makeover Mage to improve the appearance of their favourite animals. Sadly, the Mage was deeply involved in business with the Dorgeshuun, so he/she couldn't attend. Always reo


That is one line, i have about 10 more. How can I do this?

 

 

 


Reply

jlhaslip
Here is one way to do it:

CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br>
<?php

$text = "<p>Avast, ye landlubbers! Murphy at Port Khazard has discovered a new spot teeming with fish for his trawler! He can't haul in this bountiful booty by his lonesome, though. With more high-quality fishy things to catch (those with the ability to catch manta rays and turtles, for example, are likely to catch quite a few more on the trawler than they could previously), it's time to strap on your Fishing gear, fix those leaks and start reaping the rewards.<br />Bring your friends along for a voyage on the high seas, but don't be afraid to get wet! The more friends that set sail, the greater the chance of more fish. Murphy has also fashioned himself a handy bank deposit box to allow you to send your fish straight to your bank (assuming you have the space, of course)!<br />RuneScape's Group of Advanced Gardeners (G.A.G.) recently commissioned the Makeover Mage to improve the appearance of their favourite animals. Sadly, the Mage was deeply involved in business with the Dorgeshuun, so he/she couldn't attend. Always reo</p>";
$text .= '<p>Next Line Here between double quotes</p>';
$text .= '<p>Add the < \'p\' > tags as required... </p>';
$text .= '<p>One of these lines for each one you have. The \'period\' is a concatenation operator and adds each new line to the variable named text.</p>';
$text .= '<p>and escape the special characters the parser doesn(\')t like to see...</p>';

$page=$_GET['p'];
switch($page){

case 'pagetwo':
echo 'This is page two';
break;
case 'pagethree':
echo $text;
break;
default:
echo 'This is the default page';
}
?>
</body>
</html>

There is another method which I will try and see if it works as I expect, then i will post it here in a few mnutes or report that it doesn't. The second method is to "break out of php and insert the html then go back into php, but I haven't ever tried to do that in the middle of a switch statement, so I will attempt it and see if it works. smile.gif

===============
EDIT HERE
===============

This works, too:
CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<a href="?p=idx">Home</a> - <a href="?p=pagetwo">Page Two</a> - <a href="?p=pagethree">Page Three</a><br>
<?php
$page=$_GET['p'];
switch($page){

case 'pagetwo':
echo 'This is page two';
break;
case 'pagethree':
?>

<p>This is the second method and appears to works equally well.</p>
<p>Just leave php momentarilly, write the html code and then re-enter php. I didn't know if it would whack the switch statement, but it seems to be working okay.</p>
<p>Next Line Here between double quotes</p>
<p>Add the < \'p\' > tags as required... </p>
<p>One of these lines for each one you have. The \'period\' is a concatenation operator and adds each new line to the variable named text.</p>
<p>and escape the special characters the parser doesn(\')t like to see...</p>

<?php
break;
default:
echo 'This is the default page';
}
?>
</body>
</html>

Notice the different approach? I would use this one if I didn't need to parse any variables, like for example, I would use the first one if I needed to echo out a php variable as, for instance, a name or date or something.
Another issue is the volume of stuff being written. For small amount of information, stay inside php because it takes CPU cycles to leave the parser and return.

Good luck with it and post back if you need any more assistance.
And notice that I have moved the default selection to the last position in the switch? That is a good idea since it is what gets performed if there are no acceptable values in he query string, so it is the fallback action.

And consider stripping special/html characters in the user input. Adds security and a script kiddie can't hit you. Mind you, it isn't serious because you aren't accessing a Database, but you never know what sort of vulnerability can be opened up with a User playing with the query string. It is possible to insert a javascript injection if you don't scrub and sterilize the User supplied data.

====
EDIT
====
And that parse error is most likely from having the single quote / apostrophe in the text you were trying to echo. Use the backslash to escape them like in the first example I posted.

=====
EDIT
=====
Yet another method would be to "include" the data you want to have inserted.
To do this, simply create a file which conatains the html code and text you want listed and change the code for the switch=3 to something like this:
CODE
case 'pagethree':
include ("path/to/file.name");
break;


This method is untested in this example, but should work as it exists.

The file can be named anything, could have almost any extension and will be parsed as html unless it includes a set of php tags to use the php parser. Included files are ALWAYS parsed as html.

 

 

 


Reply

Imtay22
okay, Now I am trying to post a <form> Attribute in the code, for a login one. I will try the trird method. if that does not work, I will post back here.

Reply

jlhaslip
For the purpose of diagnostics, please start a new thread for your code, Imtay. It will be better that way. Sorts out things easier.

Reply

Imtay22
ok

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for , p, pageid, syntax
advertisement



Question On The "p=pageid" Syntax



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE