如何測試字符串是否是URL編碼的?測試字符串是否以PHP編碼的URL
以下方法哪個好?
- 搜索這將是編碼的字符,這是不是字符串,如果任何存在,那麼它不是編碼,或
- 使用這樣的事情,我做了:
function is_urlEncoded($string){
$test_string = $string;
while(urldecode($test_string) != $test_string){
$test_string = urldecode($test_string);
}
return (urlencode($test_string) == $string)?True:False;
}
$t = "Hello World > how are you?";
if(is_urlEncoded($sreq)){
print "Was Encoded.\n";
}else{
print "Not Encoded.\n";
print "Should be ".urlencode($sreq)."\n";
}
上面的代碼的工作,但不在字符串已經被雙重編碼的情況下,在這些例子中:
$t = "Hello%2BWorld%2B%253E%2Bhow%2Bare%2Byou%253F";
$t = "Hello+World%2B%253E%2Bhow%2Bare%2Byou%253F";
當您的PHP腳本看到它時,字符串會如何被URL編碼?例如,問題是你的腳本是否需要對傳入的字符串進行URL解碼,或者是腳本需要不對鏈接href或輸入值進行雙重編碼的問題? – 2011-11-11 23:13:04
如何使用urldecode並將其與原始字符串進行比較。如果它們匹配,它還沒有編碼。 – thedjaney 2015-09-17 05:42:56