Home >Backend Development >PHP Problem >How to remove url parameters in php

How to remove url parameters in php

Guanhui
GuanhuiOriginal
2020-05-07 16:23:595531browse

How to remove url parameters in php

How to remove url parameters in php

First use the "parse_url()" function to split the url; then reassemble the split data "scheme", "host" and "path" will do.

 $rstr='';
    $tmparr=parse_url($url);
    $rstr=empty($tmparr['scheme'])?'http://':$tmparr['scheme'].'://';
    $rstr.=$tmparr['host'].$tmparr['path'];
    return $rstr;

Or use these two functions "strpos()" and "substr()" to delete the parameters after "?".

if ($pos = strpos($url, '?') !== false) {
    $url = substr($url, $pos, -1);
}

The above is the detailed content of How to remove url parameters in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn