在php中编码包括连字符(-)和点(.)的网址 [英] Encode the url including hyphen(-) and dot(.) in php

查看:78
本文介绍了在php中编码包括连字符(-)和点(.)的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个API中进行处理的编码URL,但是它需要完整的编码URL.例如,来自以下网址的网址:

I need the encoded URL for processing in one of the API, but it requires the full encoded URL. For example, the URL from:

http://test.site-raj.co/999999?lpp=1&px2=IjN

必须成为编码的URL,例如:

has to become an encoded URL, like:

http%3a%2f%test%site%2draj%2eco%2f999999%3flpp%3d1%26px2%3dIjN

我需要对每个符号进行编码,甚至像上面的点(.)和连字符(-).

I need every symbol to be encoded, even the dot(.) and hyphen(-) like above.

推荐答案

尝试一下.在函数内部,如果您多次使用它...

Try this. Inside a function maybe if you are using it more than once...

$str = 'http://test.site.co/999999?lpp=1&p---x2=IjN';
$str = urlencode($str);
$str = str_replace('.', '%2E', $str);
$str = str_replace('-', '%2D', $str);
echo $str;

这篇关于在php中编码包括连字符(-)和点(.)的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆