참조 URL에서 사용자 이름을 가져와야합니다 (호스트 이름 다음에 리퍼러가 "/ members /"로 시작하는 경우에만)PHP에서 두 부분 문자열 사이의 문자열 가져 오기?
현재 작동하지 않지만 어떻게 작동합니까? ? URL에서 사용자의 이름
// example URL
// http://domain.com/members/john-doe/something
// note that domain.com or protocol can change
$string = $_SERVER['HTTP_REFERER'];
$start = '/members/';
$end = '/';
$startpos = strpos($string, $start) + strlen($start);
if (strpos($string, $start) !== false) {
$endpos = strpos($string, $end, $startpos);
if (strpos($string, $end, $startpos) !== false) {
echo substr($string, $startpos, $endpos - $startpos);
}
}