2015-04-06 71 views
0

通常,視頻網址類似於site.com/watch?v=abcde.flv 影片,我想新的URL是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

$ URL = $ _GET [ 'V']; $ first_five substr($ url,0,5); – Saty 2015-04-06 13:39:31

回答

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'"); 
+0

謝謝!這工作完美 – 2015-04-06 14:01:49

相關問題