Removing anchor (#hash) from URL

后端 未结 4 507
天命终不由人
天命终不由人 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:40

    Alternative way

    $url = 'http://site.com/some/#anchor';
    echo str_replace('#'.parse_url($url,PHP_URL_FRAGMENT),'',$url);
    

提交回复
热议问题