html - 确定 url 中的编码类型
问题描述
我正在解析具有以下形式的网址:
http:\/\/domain.com\/?key1=value1&key2=value2
您可以看到所有的/
都被编码为\/
和所有的&
as &
。很容易对这个替换进行硬编码以获得真正的 url,但可能有一些其他字符编码不同。我正在寻找这种编码的类型,以便我可以处理我目前无法预测的情况。你知道这个编码标准吗?
解决方案
只需对其进行逆向工程,以下是获取值所需的步骤。
$str = "http:\/\/domain.com\/?key1=value1&key2=value2";
$str = htmlspecialchars_decode($str);// Convert & to just &
$parts = parse_url($str); //Seperate Url string to its parts
parse_str($parts['query'], $params); // Parse the parts to get the query params and set them to a new out ¶ms
//Loop though different params
foreach($params as $key => $value)
{
echo $key . " = " . $value . "</br>";
}
//Output
key1 = value1
key2 = value2
推荐阅读
- sql - 更新 SQL 临时表
- javascript - 解释一下这是什么 Vue 运算符以及它的作用 <%= %>
- javascript - 从 CMS 驱动的 HTML 标记呈现 Svelte 组件的更好方法
- go - 如何处理 Gin 中间件中的错误
- css - Mat-checkbox 波纹绝对定位错误扩展容器
- solana - Solana 程序可执行数据帐户
- amazon-web-services - 如何确保 S3 不会将并行事件放入 lambda?
- sql - 无论如何要改进此 SQL 以避免多个联接
- c - 无法在powershell中运行exe
- google-analytics - 自动将 Google Analytics 表转移到不同的 BigQuery 项目