I am trying to get content from file at home directory and want to avoid absolute path using tilde in path
I have created file in shell
echo "test" > ~/test_file.txt
Then I am trying to read the file with PHP file_get_contents()
file_get_contents('~/test_file.txt')
Getting following PHP error
Warning Error: file_get_contents(~/test_file.txt): failed to open stream: No such file or directory
Update
This is duplicate of https://stackoverflow.com/a/1894954/2686510
Code snippet I use now
$home = getenv("HOME");
file_get_contents($home . DIRECTORY_SEPARATOR . 'test_file.txt');