Walrus
Walrus

Reputation: 20444

Get content after question mark in PHP if statement

I am setting up a separate theme page for printable content. To tell the browser to use the print theme I'm using a mark ?print after the URL. So how does one get that content?

Something link

<?php if (? = 'print') {
   blah blah }

Any ideas?

Marvellous

Upvotes: 1

Views: 5761

Answers (4)

David Gillen
David Gillen

Reputation: 1172

Are you aware you can just set up a stylesheet for printing, this may suffice for your needs. Just add a line like the following after your standard css line.

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

Upvotes: -2

ThiefMaster
ThiefMaster

Reputation: 318518

You can access the whole query string using $_SERVER['QUERY_STRING'].

So your code could look like this:

if($_SERVER['QUERY_STRING'] == 'print') { /* do something */ }

Upvotes: 3

alex
alex

Reputation: 490283

You use $_GET array to access that.

If you want the whole string, use $_SERVER['QUERY_STRING'].

In your example, you'd do something like this...

if (isset($_GET['print'])) {
    // something.php?print
};

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382726

You need to use $_GET:

$_GET['print']

An associative array of variables passed to the current script via the URL parameters.

Note: Beware of security though, you need to sanitalize and validate any data coming from the URLs.

Upvotes: 0

Related Questions