Removing anchor (#hash) from URL

后端 未结 4 509
天命终不由人
天命终不由人 2021-01-02 09:11

Is there any reliable way in PHP to clean a URL of anchor tags?

So input:

http://site.com/some/#anchor

Outputs:

http://site.com/some/

4条回答
  •  甜味超标
    2021-01-02 09:42

    There is also one other option with parse_url();

    $str = 'http://site.com/some/#anchor';
    $arr = parse_url($str);
    echo $arr['scheme'].'://'.$arr['host'].$arr['path'];
    

    Output:

    http://site.com/some/
    

提交回复
热议问题