URL의 마지막 부분을 얻으려면 PHP에서 preg_match()를 사용하십시오. 다음이 입력 URL이라고 가정해 보겠습니다.
$websiteAddress='https://www.tutorialspoint.com/java/java_questions_answers/9989809898';
숫자
인 마지막 부분만 포함하여 다음 출력을 얻어야 합니다.9989809898'
예시
다음은 URL
의 마지막 부분을 가져오는 PHP 코드입니다.<!DOCTYPE html>
<html>
<body>
<?php
$websiteAddress='https://www.tutorialspoint.com/java/java_questions_answers/9989809898';
if(preg_match("/\/(\d+)$/",$websiteAddress,$recordMatch)){
$lastResult=$recordMatch[1];
}
echo "The result is as follows:",$lastResult;
?>
</body>
</html> 출력
그러면 다음과 같은 출력이 생성됩니다.
The result is as follows:82345999