html & php question (get command)
Want to include another value in my urls
so far I have
# valid pages
$page = array('splash', 'portraits', 'weddings', 'studio', 'about', 'mobile', 'personal');
# validate GET, default to splash if not provided
$_GET['q'] = (isset($_GET['q'])) ? strtolower(trim($_GET['q'])) : 'splash';
if (!in_array开发者_运维知识库($_GET['q'], $page))
$_GET['q'] = 'splash';
require_once "{$_GET['q']}.html";
but I want to include sections into my site so I need an extra value (ie. ?q=portraits?z=studio )
I assume I could probably just duplicate the $get command and replace q with z... but suppose I don't want the second value to be necessary (so the default pages will display without extra commands) and i want it to target a div or frame within the page? Not sure if I can even target divs.
Just use a default value:
if (isset($_GET['z'])) {
$z = $_GET['z'];
}
else {
$z = NULL; // or 'default' or whatever you want.
}
You can in short write the above in one line:
$z = isset($_GET['z']) ? $_GET['z'] : NULL;
I am not sure what you mean with "target a div", but if you mean an anchor, you can do that via identifiers (id
).
Call your PHP script via index.php?q=splash#text
and in your splash.html
file you somewhere have <div id="splash">
. The browser should scroll there.
精彩评论