당신은 간단한 정규식을 사용할 수 있습니다
이 시도 문자열을 채우고 배열에 채워 넣습니다.
end() 함수는 배열의 마지막 요소를 반환하기 때문에 마지막 텍스트 섹션 만 보는 결과가 나타납니다. 실제로하고 싶은 것은 을 제외한 모든 섹션을 얻는 것입니다. 마지막 부분은입니다. 맞습니까?
당신은 당신이에있을 것처럼 보이는 길을 계속하려는 경우, 문자열로 다시 배열을 재결합하여이 작업을 수행하지만, 최종 멤버없이 할 수
:
// Set the string with initial content
$string = "Clothing, Shoes & Accessories:Men's Clothing:T-Shirts";
// Explode the string into an array with 3 elements
$testArray = explode(':', $string);
// Make a new array from the old one, leaving off the last element
$slicedArray = array_slice($testArray, 0, -1);
// Implode the array back down to a string
$newString = implode(':', $slicedArray);
것은 아마 쉬울 것 구분 기호 문자의 마지막 발생을 검색하고 거기에서 문자열의 문자를 제거하지만 유스 케이스에 맞는지 아닌지는 잘 모르겠습니다. 완전성을 위해 다음과 같이 할 수 있습니다.
// Set string with content
$string = "Clothing, Shoes & Accessories:Men's Clothing:T-Shirts";
// Get index of last : character in the string
$lastIndex = strrpos($string, ':');
// Set new string to left portion of original string up til last : char
$newString = substr($string, 0, $lastIndex);
출처
2016-08-12 05:57:05
Jan
정확하게 보존 하시겠습니까? 옷이나 티셔츠 부분? – Jan