title: Test if string is URL encoded in PHP
body: <p>How can I test if a string is URL encoded?</p>
  
  <p>Which of the following approaches is better?</p>
  
  <ul>
  <li>Search the string for characters which would be encoded, which aren't, and if any exist then its not encoded, or </li>
  <li>Use something like this which I've made:</li>
  </ul>
  
  <pre><code>
  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";
  }
  </code></pre>
  
  <p>The above code works, but not in instances where the string has been doubly encoded, as in these examples:</p>
  
  <ul>
  <li><code>$t = "Hello%2BWorld%2B%253E%2Bhow%2Bare%2Byou%253F";</code></li>
  <li><code>$t = "Hello+World%2B%253E%2Bhow%2Bare%2Byou%253F";</code></li>
  </ul>