PHP file handling

I very green at PHP coding but i need to make a user interface through some html stuff so php would very convienient to use.
What im trying to do is open a file, and parse its content as a string, but it appears the readfile creates some wierd way of handling the file stream. What happens is the stream correctly copies it self to a variable, but first time i iterate through that variable, the stream pointer moves to the end of the files content and prints only the last byte the second time i access the stream.
e.g.
file contains
"Hello World"

<?php
$string = readfile('/path/to/some/file');
echo $string; //Here the echo prompts properly the "Hello World"
echo $string; //Here the string prompt d
?>
The above example is not my actual code, im actually making a parser which can show partitions of the system in linux by parsing an bash generated xml file, but the base idea is the same where the
pointer in the stream basically moves from start to end after accessing it and stays there.
Any ideas or help would be useful.

It's been a long time since I've touched PHP, but that doesn't make any sense. Echoing a variable does not change the variable's value. And if you're wanting a file stream use fopen(), fread(), etc. family of functions.

Im trying to make a string object from a file stream.
It is the string from the file content i need to parse.

Are you looking to parse the file line by line? You could do something like this:

$file = file_get_contents("partitions.xml");
$lines = explode('\n', $file);

foreach ($lines as $line) {
    // .. parse line
}

or if you want to do something more native to XML, you could use SimpleXML:
http://blog.teamtreehouse.com/how-to-parse-xml-with-php5

After a bunch of code crunshing i got it working now. My original problem was getting simplexml api working, but after hours of reading posts on the interwebz it now works.
Basically i was trying to implement a parser which i created myself since i for the love of me couldn't get simplexml to work, but turns out its not installed by default(Like i wrote im very green at php).
Even after i installed the simplexml api i had problems getting it working and spent hours where my code executed perfectly in console, but if i executed it as a php page in a browser, it simply didnt execute, even though phpinfo() told me the module was loaded. Finally did a reboot and voila it worked perfectly first try.

i used a solution more or less like what you describe, except i can call the xml children directly and get their names with simplexml.
$xml=simplexml_load_file(somePath) or die("Woops i exploded");

foreach($xml->children() as $child)
{
do something with $child->getName();
}

Just my 2 cents: but you might want use file_get_contents to read the file and the use json_decode and json_encode since these 2 function convert the content string to a php variable and vice versa more easily than xml.

im just converting the contents of the xml children into a table. The xml file i use i generated by a bash script which runs seperately of the web interface, i never have to write any xml to the file from the interface.
I found a method which can execute the shell script while running which is my next implementation, so i can call the script the ask the page to update the table content again from a newly generated xml file.

I highly, HIGHLY recommend DOM over SimpleXML.

From what i read DOM i mainly focused at parsing stuff like HTML and so on, where simplexml is focused directly on XML data, at any rate i extract the data from the bash generated file i want, and need. And i really dont want to overcomplicate it, i solved my current problem with 15 lines of injected code into a html page. Im not looking to use Json, or change API's cause the card house is currently standing stable.
I can understand the idea behind DOM though since it was originally developed as a frame work for generic document parsing. Im using a very specific written dataset though, and since i create the bash code, and the html, i can pretty much do what i want with the dataset i extract and inject. And calling xxx->getChild()->getName() to get my data string is about as dumbed down as i've tried in my 4 years of studying software engineering.

Tread carefully.