【问题标题】:Query string in php codephp代码中的查询字符串
【发布时间】:2013-06-20 00:30:31
【问题描述】:

如何将查询字符串名称放入php?

$file_get_html('http://localhost/search/?q=');

当访问 localhost/?name=example 时,代码如下所示

$file_get_html('http://localhost/search/?q=example');

我不知道如何将$_GET['url'] 放入 php 中 :(

【问题讨论】:

  • file_get_html($_GET['url']); - 如果这真的是你的意思。
  • file_get_html之前没有$
  • 这个问题不是很清楚。您是否尝试将收到的查询字符串与其他 URL 合并?
  • 我没有遵循你想要的。 URL 的参数与您显示的参数 q 有什么关系?你能更好地解释一下你想要做什么吗?
  • <?php // setup require_once('simple_html_dom.php'); // get DOM from URL or file $html = $file_get_html('http://localhost/serarch/?q='); ?> 想使用 Simple HTML DOM Parser 来提取页面的数据。然而,这个页面是seek的结果。所以,我替换了我的 url 中的变量,即站点 url [search]。

标签: php variables get query-string


【解决方案1】:

这个问题不是很清楚,但我怀疑这就是答案:

file_get_html('http://localhost/search/?q=' . urlencode($_GET['url']));

【讨论】:

  • 注意:未定义变量:第 7 行 C:_server\htdocs\test.php 中的 file_get_html 致命错误:函数名称必须是第 7 行 C:_server\htdocs\test.php 中的字符串7:$html = $file_get_html('http://localhost/bsearch/?q=' . urlencode($_GET['movie']));
  • 你没看到我一个小时前写的评论吗?在file_get_html() 之前不应该有$
  • 哦,对不起。工作。我认为file_get_html 前面的$ 是扩展的标准
  • $ 用于 PHP 中的变量,我不知道您从哪里得到它与扩展有关的想法。
  • 虽然我对PHP知之甚少,但我知道$都是PHP变量。但是,我认为扩展程序有必要运行$。无论如何。
【解决方案2】:

?q=example 将允许您使用类似 $example = $_GET['q'] 的东西, 并且 $example 应该等于查询字符串中 q 的值。

如果您有一个如下所示的查询字符串:

?q=example&url=myurl.com

您可以像这样访问 q 和 url 参数:

$q = $_GET['q']; // which will equal 'example'
$url = $_GET['url']; // which will equal 'myurl.com'

如果那是你想要做的。

【讨论】:

  • 但是如何输入$file_get_html
【解决方案3】:
$url = urlencode($_GET['url']);
$contents = file_get_contents("http://localhost/search/?q={$url}");

var_dump($contents);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多