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