php file()不使用绝对url

I am using this code to write a line from a file to a page. It works when I write the php like this:

<?php
$f_contents = file("something.txt"); 
$line = $f_contents[array_rand($f_contents)];
$data = $line;
echo "$data";
?>

But not like this:

<?php
$f_contents = file("http://something.com/something.txt"); 
$line = $f_contents[array_rand($f_contents)];
$data = $line;
echo "$data";
?>

Why isn't it working, and how can I fix it?

You don't want to use the URL. You want to use the full file path. This is the file path from the root directory on your server. I can't tell you what that is because I do not have access to your server but it would look something like this:

/root/path/to/wwwroot/something.txt

There are many ways to find out the path to a file. You can do it programmatically in PHP by placing a file in the same directory with the following contents:

<?=__DIR__ ?>

Then open it in a browser.

Your webhosting control panel should also be able to tell you. Same for an FTP client or SSH command line.