I running a simple mysql query and trying to grab from the src column but I only want to grab the "video#.mp4" part - not the whole value (see picture attached below)
If anyone knows how to achieve this... I really appreciated it! Thank you for any help!
Code:
$con=mysqli_connect("localhost","test","123","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT id, title, src, type, poster_img FROM TABLE_NAME";
if ($result=mysqli_query($con,$sql))
{
$id = 0;
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
// Show video#.mp4 here ///
echo '';
$id++;
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
I suggest you to store quality
and video name
in 2 different columns, because this will help you in searching etc.
In your example, you can achieve your desired result by using json_decode
but again, it will work if you have valid json
in src
column.
Example:
$string = '[{"quality":"default","mp4":"video2.mp4"}]';
$array = json_decode($string,true);
print_r($array);
Result:
Array ( [0] => Array ( [quality] => default [mp4] => video2.mp4 ) )
Now you can get the index mp4
easily, if you have multiple file format, than you can group than inside your loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.