I get this error when I try to get content from youtube with more then one word.
Warning: file_get_contents(https://www.youtube.com/results?search_query=html begginer): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\sites\mime\beta\default.php on line 5
My code:
<?php
$address = $_GET['q'];
$address = 'https://www.youtube.com/results?search_query=' . $address;
$html = file_get_contents($address);
echo $html;
?>
However, if I try to get content from youtube using only one word (for example: http://127.0.0.1/sites/mime/beta/default.php?q=html
), the script work perfectly.
What's wrong?