html& PHP的问题(得到命令) [英] html & php question (get command)

查看:107
本文介绍了html& PHP的问题(得到命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在我的网址中加入另一个值



到目前为止我有

 #有效页面
$页面= array('splash','portraits','weddings','studio','about','mobile','personal');

验证GET,如果未提供,则默认为启动
$ _GET ['q'] =(isset($ _ GET ['q']))? strtolower(trim($ _ GET ['q'])):'splash';
if(!in_array($ _ GET ['q'],$ page))
$ _GET ['q'] ='splash';

require_once{$ _GET ['q']}。html;

但我想将部分加入我的网站,所以我需要一个额外的值(例如?q =肖像?z = studio)

我假设我可以复制$ get命令并将q替换为z ...但假设我不想要第二个值是必要的(所以默认页面将显示没有额外的命令),我希望它的目标在页面内的div或框架?不知道是否我可以针对div。

解决方案

仅使用默认值:

  if(isset($ _ GET ['z'])){
$ z = $ _GET ['z'];
}
else {
$ z = NULL; //或'默认'或任何你想要的。
}

您可以简单地在上面写一行:

  $ z = isset($ _ GET ['z'])? $ _GET ['z']:NULL; 

我不确定你的意思是瞄准一个div,但如果你的意思是一个锚点,你可以通过标识符( id )来实现。



通过 index调用你的PHP脚本.php?q = splash#text ,并且在您的 splash.html 文件中,某处有< div id =飞溅> 。浏览器应该在那里滚动。


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.

这篇关于html&amp; PHP的问题(得到命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆