Jump to content

Very simple GET help


MrCreeky

Recommended Posts

I just want to show an area on a page if the GET string is set to true i.e. .php?string=true

<?php 
$string == $_GET
if ($string === "true") {
}
else {
}
?>

That's what I came up with after quickly looking at my book but it errors. Could someone show where where I'm going wrong. This is very simple I'm sure but I don't do much php coding.

Link to comment
Share on other sites

<?php
$foo =  isset($_GET['string']) ? $_GET['string'] : null;
if(!is_null($foo)) {
      echo 'true';
} else {
echo 'false';
}

 

Using this works just fine for my page but how would I be able to use html with the echo output without having to comment out parts like this: class=/"none/" ?

Link to comment
Share on other sites

You can tkae  alook at the heredoc syntax;

 

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

 

This will allow you to do the following...

 

<?php
$foo =  isset($_GET['string']) ? $_GET['string'] : null;
if(!is_null($foo)) {
echo <<<EOD
<span class="whatever">'single quotes as well'</span>
EOD;
} else {
echo <<<EOD
<span class="whenever">'single quotes as well'</span>
EOD;
}

Link to comment
Share on other sites

<?php
$foo =  isset($_GET['string']) ? $_GET['string'] : null;
if(!is_null($foo)) {
   echo <<<EOD

<table width="1000000">
    <tr>
        <td>You could fit a big table in here!</td>
    </tr>
</table>

   EOD;
} else {
   echo <<<EOD
<span class="whenever">'single quotes as well'</span>
EOD;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.