Here is my problem:
I got a text table that has a text file like this:
----start----
name
workstep
workstep
workstep
.
.
-*--
status
--*--
comment
comment
.
.
---*--
part
part
.
.
---end----
Now I need to split this text file into lines. I got no experience with how MySQl delivers the text file. I expect to get a newline and ch.return
So I thought to first explode each part at the marks (e.g. -*--) and then explode it by the newline char if that is possible but I suspect there might be a more elegant way.
is there a function like fget for strings?
Any ideas?
MySql text table retrieve
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
maybe you're looking for something like this: viewtopic.php?t=37400 ?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
an SQL file isn't really breakable by lines as tables are often created using multiple lines, insertion queries could take multiple lines, etc. Yes, explode() is faster than preg_split() but preg_split() is 1000 times more flexible as I illustrated in that thread, which seems to have a nearly identical goal. If you simply want to break the file apart into literal lines, then file() does that natively, but if you want the individual commands that would be run, the solution provided in the linked thread would be the starting place to work from most likely.
I totally agree that preg_split is way more flexible but in this case those files are created by an application to be saved to the harddisk. As the table structure is very complex and I don't have the source of the application I created a little tool to be run by the client which places that file into a database I got access to. I decided to use that way and not to move the whole file due to security reasons.
Therefore the file is always in the same structure and is placed in the database as whole. So basically I could use preg_split as well as explode as time is not an issue but I find it easier to use explode.
Therefore the file is always in the same structure and is placed in the database as whole. So basically I could use preg_split as well as explode as time is not an issue but I find it easier to use explode.