Test if string is URL encoded in PHP

前端 未结 13 2205
不思量自难忘°
不思量自难忘° 2021-01-01 11:10

How can I test if a string is URL encoded?

Which of the following approaches is better?

  • Search the string for characters which would be encoded, which
13条回答
  •  再見小時候
    2021-01-01 11:50

    private static boolean isEncodedText(String val, String... encoding) throws UnsupportedEncodingException { String decodedText = URLDecoder.decode(val, TransformFetchConstants.DEFAULT_CHARSET);

        if(encoding != null && encoding.length > 0){
            decodedText = URLDecoder.decode(val, encoding[0]);
        }
    
        String encodedText =  URLEncoder.encode(decodedText);
    
        return encodedText.equalsIgnoreCase(val) || !decodedText.equalsIgnoreCase(val);
    
    }
    

提交回复
热议问题