You can use file_get_contents on any type of file to pull the data as a string. If you have allow_url_fopen enabled, this can also be a remote file (but it will return whatever the parsed output is by the server).
If you mean you want to run a .txt file as if it were php code then yes. Read the file into a variable and then run that through the eval() function.
I can't really think of anything to write here now...
Im guessing you are checking what output the .txt file provides and not the actual contents:
echo("1"); // you want to get the 1 and not the full string?
If you do, there is another way that you could possibly use. You could set the .txt files as executable on your server. You can do this by modifying (or creating) a .htaccess file and adding the following:
This will make a file called test.txt executable as php.Code:<Files test.txt> AddType application/x-httpd-php .txt </Files>
However, if you are running user supplied code, IE not code you wrote. I strongly recommend NOT following this approach, or indeed even the eval approach as it is a massive security risk.
You could then get the result of the page like this:
$result = file_get_contents("http://mydomain.com/test.txt");
Your question is not very clear. From whatever I understand, idalatob gave you the answer you are looking for.
However, I should warn you, you are not making a very efficient code and probably not following the best practices. There is overhead associated with parsing a PHP file compared to a text. html file etc. When a newbie want to parse .txt as PHP, it is a clear sign of poor logic and poor idea about optimization. If something is ever meant to be parse, it is better off being saved as .php. Get your basics and logic correct, try to find the simplest solution. KISS is a cliched, still very valid philosophy when it comes to programming.