php - 抓取带有特殊字符的 URL 参数
问题描述
我使用以下方法从 URL 中获取参数:
<?php echo $_GET['compname']; ?>
我刚刚注意到一些参数包含特殊字符,所以我尝试使用以下内容:
<?php echo urlencode($_GET['compname']); ?>
但是输出看起来像这样:
COMPANYNAME+LLC+LTD
如果公司名称有特殊字符(例如:COMPANY & SONS),输出将如下所示:
COMPANY+
我尝试使用这样的 HTMLENTITIES:
<?php echo urlencode(htmlentities($_GET['compname'])); ?>
但我得到相同的结果
COMPANY+
我尝试使用以下网站中的示例:
https://www.php.net/manual/en/function.htmlentities.php
这是我的尝试:
<?php echo urlencode(htmlentities($_GET['compname'], ENT_QUOTES)); ?>
但我得到了相同的结果:
COMPANY+
我需要让结果看起来像这样:
COMPANY & SONS
我做错了什么,我该如何解决?
解决方案
<?php
$_GET['compname']="this+is+a+test+for+you";
echo urldecode($_GET['compname']); // decode this is a test for you
?>
推荐阅读
- php - 如何从 EXCEL 中获取 PHP 中的分组行?
- visual-studio - 如何打开/关闭 .NET Core 应用程序的 Docker 支持?
- ios - 更改 UINavigationBar 的前导边距和后边距
- php - SQLSRV 参数化查询在 GROUP BY 子句中永远存在
- python - 试图将 5 个卡值传递给函数,但不起作用
- tsql - 按时间段分组记录
- java - 使用 Firebase 的聊天应用
- kendo-ui - 资源的 Kendo Scheduler TimeLineView,将每个事件显示为好像它的 allDay 事件
- c# - 以编程方式下载电子邮件附件 C# WPF
- vba - VBA:运行时错误“438”:对象不支持此属性或方法