내 URL에서 숫자 uri 문자열의 마지막 발생을 대체하는 데 도움이 필요합니다. 예를 들어 다음과 같은 URL 문자열이 있습니다.
$url1 = "http://localhost/mystore/electronics/company/5-mobile/5";
$url2 = "http://localhost/mystore/electronics/company/5-mobile/21";
$url3 = "http://localhost/mystore/electronics/company/5-mobile";
여기에서 "/ 5"또는 "/ 21"또는 빈 문자열로 마지막 슬래시 다음의 다른 숫자를 제거하고 다음 만 가져옵니다.
$url1_after_preg_replace = "http://localhost/mystore/electronics/company/5-mobile";
$url2_after_preg_replace = "http://localhost/mystore/electronics/company/5-mobile";
$url3_after_preg_replace = "http://localhost/mystore/electronics/company/5-mobile";
도움을 주셔서 미리 감사드립니다.
preg replace를 사용하지 않고 간단한 방법 :
if(explode(dirname($url1),$url1)[1] != "/5-mobile") {
$url1_after_preg_replace = dirname($url1);
}
참조 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다