如何测试字符串是否是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