gpt4 book ai didi

php - 在 php 中对包含连字符 (-) 和点 (.) 的 url 进行编码

转载 作者:行者123 更新时间:2023-12-02 23:35:56 25 4
gpt4 key购买 nike

我需要编码的 URL 以便在其中一个 API 中进行处理,但它需要完整的编码 URL。例如,URL 来自:

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

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

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

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

最佳答案

试试这个。在函数内部,如果您多次使用它,也许......

$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 - 在 php 中对包含连字符 (-) 和点 (.) 的 url 进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12093050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com