Checking for relative vs absolute paths/URLs in PHP

前端 未结 7 630
既然无缘
既然无缘 2021-01-17 15:45

I need to implement functions to check whether paths and urls are relative, absolute, or invalid (invalid syntactically- not whether resource exists). What are the range of

7条回答
  •  死守一世寂寞
    2021-01-17 16:26

    If you already know that the URL is well formed:

    if(strpos($uri,'://')!==false){
        //protocol: absolute url
    }elseif(substr($uri,0,1)!='/'){
        //leading '/': absolute to domain name (half relative)
    }else{
        //no protocol and no leading slash: relative to this page
    }
    

提交回复
热议问题