通常,视频网址与site.com/watch?v=abcde.flv
相似
我希望新网址为site.com/watch?v=abcde
通常是:
$url = $_GET['v'];
然后
$query = mysql_query("SELECT * FROM videos WHERE url = '$url'");
我怎么才能只使用前5个字符?
这是我尝试过的,但它不起作用:
$newurl = substr($url, 0, 11);
然后
$query("SELECT FROM videos WHERE substring(url, 0,11) = '$newurl'");
答案 0 :(得分:0)
SQL中用于字符串解析的正确语法是:
LEFT ( character_expression , integer_expression )
有关详情,请参阅: https://msdn.microsoft.com/en-ca/library/ms177601.aspx
在你的情况下:
//assuming your new url of watch?v=abcde
$url = $_GET['v'];
//assuming the video in your databse is stored as abcde.flv
$query = mysql_query("SELECT FROM videos WHERE LEFT(url,5) = '$url'");