Test if string is URL encoded in PHP

前端 未结 13 2242
不思量自难忘°
不思量自难忘° 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:32

    What about:

    if (urldecode(trim($url)) == trim($url)) { $url_form = 'decoded'; }
      else { $url_form = 'encoded'; }
    

    Will not work with double encoding but this is out of scope anyway I suppose?

提交回复
热议问题