function getArticleID($url) { $parts = explode('/', $url); return $parts[2]; } $url = 'https://example.com/article/12345/my-amazing-article'; $id = getArticleID($url); echo $id; // outputs 12345
function getArticleID($title) { $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password'); $stmt = $pdo->prepare("SELECT id FROM articles WHERE title = ?"); $stmt->execute([$title]); $result = $stmt->fetch(); return $result['id']; } $title = 'My Amazing Article'; $id = getArticleID($title); echo $id; // outputs the ID of the article with title "My Amazing Article"Package/Library: This function does not seem to be part of any specific package or library, as it is a simple custom function that can be included in any PHP project.