我如何通过$ _GET获取参数

时间:2013-09-11 03:29:22

标签: php html utf-8

我无法获取参数$_GET,其值包含字符:'#'。

我有以下代码:

<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: #ff0000;">Empty content.</span>">

当我改变或消除角色时:'#'一切正常。例如:

<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: ff0000;">Empty content.</span>">

如何让参数(text_content)值完整?

注意:我正在测试 PHP 获取此参数/值$_GET['text_content']

由于

3 个答案:

答案 0 :(得分:4)

一旦你从$ _GET中获取它们,你就会想要urlencode()通过GET请求传递的任何字符串和urldecode()它们。

http://www.php.net/manual/en/function.urlencode.php

字符串中的引号也会导致问题。试试你的热门iframe:

<iframe src="http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=%3Cspan%20style%3D%22color%3A%20%23ff0000%3B%22%3EEmpty%20content.%3C%2Fspan%3E">

答案 1 :(得分:0)

您需要使用url_encode函数,因为#之后的任何内容都不会被视为URL的一部分(浏览器不会将该部分发送到服务器)。

答案 2 :(得分:0)

你应该在将urlencode发送到php脚本进行处理之前使用它,然后使用urldecode正常输出它。

也许试试:

<iframe src="<?php urlencode('http://localhost/wp352/wp-content/plugins/heloworld/templates/options-rte.php?text_content=<span style="color: #ff0000;">Empty content.</span>'); ?>">

获取它:

urldecode($_GET['text_content']);