url에서 중복 검색어 문자열을 제거하는 방법은 무엇입니까? 따라서, 문자열을 아래와 같이PHP에서 문자열의 특정 부분 (중복 querystring)을 제거하는 방법?
,
URL :
localhost.com/en_ar/body?products_type=235&treatment=132?product_type=235&treatment=132&__from_store=en_bh
얻어진 URL :
localhost.com/en_ar/body?product_type=235&treatment=132&__from_store=en_bh
방법 PHP를 사용하여 쿼리 문자열에있는 경우
?content?
사이 캐릭터 컨텐츠의 제 1 부분을 제거하는
.
우리의 경우 문자열에서 내용 ?products_type=235&treatment=132?
을 제거하십시오.
(\?(?<=\?).*(?=\?))
그것은 ?
주위를 보면 1 ?
과 함께 ?
2 사이의 모든 내용과 일치합니다 :
귀하의 코드는 나를 위해 작동하지 않습니다 첫 번째 대답으로. –
$ url = "localhost.com/ko_ar/body?abcd?products_type=235&tr==323product_type=235&treatment=132&__from_store=en_bh"; \t echo preg_replace ('/ \? [^?] * /', '', $ url, 1); –
출력은 다음과 같습니다. localhost.com/en_ar/body?product_type=235&treatment=132&__from_store=en_bh 은 마지막 쿼리 문자열을 제외한 모든 쿼리 문자열이 제거됨을 의미합니다. –