Jump to content
xisto Community
Sign in to follow this  
Imtay22

Question On The "p=pageid" Syntax

Recommended Posts

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

<!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-
case 'pagethree':echo 'This is page three<br>Cool, huh?';

When I try to do that, I get the error-

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-
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?

Share this post


Link to post
Share on other sites

Here is one way to do it:

$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' linenums:0'><!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. :P

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

This works, too:
switch($page){

case 'pagetwo' linenums:0'><!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><?phpbreak;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:
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.