Jump to content

String Streams In Php


boen_robot

Recommended Posts

I've been recently writing a new teplating engine for myself... among one of the requirements I set to myself is to work equally well with files, and just-in-time strings. I've done a little with C++'s fstream, cin/cout/err and stringstream objects, and I know for a fact PHP has equivalents for the first two, which are readable and writable with fread() and fwrite() respectively. However, I just reached a road block on the third... is there a way I could open an empty stream, without associating it with a file (temporary or otherwise), or in other words, could I create a string stream? If so, how? I expect to use quite a few such streams if possible, so using temporary files will leave the OS really unclean.[edit]Well, I found the tmpfile() funciton... but that would still create a file (even though a temporary one)... is there a better way?[/edit]

Link to comment
Share on other sites

It looks like C++'s stringstream is just a wrapper to work with a string as if it were a stream, what differences are you expecting in PHP between a string as a stream vs. just using a string in memory? Are you just looking for a wrapper like with C++ where you have code that works on streams and you want to use the same code for a regular string?Look into opening a stream using the php://memory or php://temp wrappers:http://www.php.net/manual/en/wrappers.php.phpAlso the data wrapper:http://www.php.net/manual/en/wrappers.data.php

Link to comment
Share on other sites

Are you just looking for a wrapper like with C++ where you have code that works on streams and you want to use the same code for a regular string?
Exactly. I have a piece of code that works with streams, and I want to use it within another piece of code. The other function will give the stream function a string stream, and will then post-process the resulting string stream.php://temp suits the situation perfectly. Thanks.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...