skip to Main Content
$site = file_get_contents("https://www.youtube.com/@PewDiePie"); 

I’m pulling data from youtube with file_get_contents. but since the language setting and IP address of my hosting service are Turkey, when I use file_get_contents, a Turkish page appears.

How can I view the content in English?

2

Answers


  1. Chosen as BEST ANSWER

    This solved my problem:

    $newurl="https://www.youtube.com/@PewDiePie";
    $opts = [
        "http" => [
        "method" => "GET",
            "header" => "Accept-language: enrn" .
                "Cookie: hl=enrn"    ]];
    $context = stream_context_create($opts);
    $file = file_get_contents("$newurl", false, $context);
    echo "$file";
    

  2. Just use hl in your URL’s query string.

    In below example I used hl=en for English language!

    The persist_hl=1 is for preserving language after redirection!

    $site = file_get_contents("https://www.youtube.com/@PewDiePie?hl=en&persist_hl=1"); 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search