如何获取URL参数中的网址?

通过PHP的urlencode

使用urlencode 可以实现接口访问中参数值为URL网址的情况。
解决了字符串中由于敏感字符无法传参的问题。
描述:

  • urlencode ( string $str ) : string
    This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
    urlencode()编码:对字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。
    urldecode()解码:还原 URL 编码字符串。
    示例:
<?php
echo urlencode("https://dfq.talk.com/test.html?user=blackbox&room=5ca481e99a88ab02be37bdf3&console=true");
?>
//输出结果如下。
//https%3A%2F%2Fdfq.talk.com%3A3004%2Ftest.html%3Fuser%3Dblackbox%26room%3D5ca481e99a88ab02be37bdf3%26console%3Dtrue
//如果想查看原网址,使用urldecode()解码即可。

参考链接:
https://blog.csdn.net/resilient/article/details/83177100

通过JavaScript的encodeURI()、encodeURIComponent()函数

示例

$scope.send_email_invite=function(){
	var inviteUrl=encodeURIComponent(location.href);
	var email=$(".email_value").val();

	const Http = new XMLHttpRequest();
	var send_email_url = "https://dfq.test.com/send_email.php?name="+$scope.localUserName+"&email="+email+"&url="+inviteUrl;
	Http.open("GET",send_email_url);
	Http.send();

	Http.onreadystatechange = function ( ) {
		if (this.readyState == 4 && this.status == 200) {
			var HttpResponseObj = JSON.parse(Http.responseText);
			console.log(HttpResponseObj);
		}
	}
}

在这里插入图片描述
参考链接:
https://www.w3school.com.cn/jsref/jsref_encodeuri.asp
https://www.cnblogs.com/seasons1987/p/3357775.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值