簡體   English   中英

在 PHP 字符串中,如何將非字母數字字符轉換為十六進制 ascii

[英]in PHP string, how to convert non-alphanumeric characters to ascii in hex

比如怎么寫一個 PHP function 來轉換

http://abc.com/hi-1?source=google

被轉換成

http%3A%2F%2abc.com%2Fhi-1%3Fsource%3Dgoogle

PS有些異常不應該被轉換,比如'.' '-'

謝謝。

http://php.net/manual/en/function.urlencode.php
或者
http://www.php.net/manual/en/function.rawurlencode.php

<?php
$string = "http://abc.com/hi-1?source=google";
echo urlencode($string); //echo rawurlencode($string);

http://php.net/manual/en/function.rawurlencode.php

echo rawurlencode("http://abc.com/hi-1?source=google");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM