Is there any way to treat a string like a file in PHP?
For example...I have a string: $str = "Hi, I'm a string in php";
and I have a file "hi.txt" and its contents are "Hi, I'm a file in php".
Now with hi.txt, I can do all kinds of file operations like fgetcsv().
Is there any way that I can do these operations on the string? Sort of trick PHP into thinking that $str is actually a file that I can get a $handle on.
treat a string like a file
Moderator: General Moderators
Re: treat a string like a file
Either save the string as a file or use string methods to emulate the file methods available in php. I find it hard to see why you would want to do that though, aside from fgetcsv - which has its string equivalent http://www.php.net/manual/en/function.str-getcsv.php
Re: treat a string like a file
The server that I am on cannot write to the file system, so everything has to be saved to the db.
I tried the str_getcsv() but I got "Call to undefined function str_getcsv()"
I'm running PHP 5.1.2
I tried the str_getcsv() but I got "Call to undefined function str_getcsv()"
I'm running PHP 5.1.2
Re: treat a string like a file
Check out the comments section in the documentation page I linked you to, there are some custom implementations of csv parsing functions.