我从https://www.codexworld.com看过这段代码,可以使用PHP创建URL缩短器。
// Include database configuration file
require_once 'dbConfig.php';
// Include URL Shortener library file
require_once 'Shortener.class.php';
// Initialize Shortener class and pass PDO object
$shortener = new Shortener($db);
// Long URL
$longURL = 'https://www.codexworld.com/tutorials/php/';
// Prefix of the short URL
$shortURL_Prefix = 'https://localhost/'; // with URL rewrite
$shortURL_Prefix = 'https://localhost/?c='; // without URL rewrite
try{
// Get short code of the URL
$shortCode = $shortener->urlToShortCode($longURL);
// Create short URL
$shortURL = $shortURL_Prefix.$shortCode;
// Display short URL
echo 'Short URL: '.$shortURL;
}catch(Exception $e){
// Display error
echo $e->getMessage();
}
我已经了解了系统的运行方式,但不知道这行代码$longURL = 'https://www.codexworld.com/tutorials/php/';
不会基于静态值,而是通过收集链接(用户将在其中使用文本框输入内容在其中键入内容)来动态化的表格吗?
我该怎么做?预先谢谢你!