Reputation: 13
I have txt file which looks like
Name: Long valueName2: Long loooooooong valueName3: short value
I need to parse it and insert to a database which looks like this
_____________________________________________________
|id |Name | Name2 |Name3 |
|1 |Long value |Long loooooooong |short value|
------------------------------------------------------
How can I do this? Is it any standard function in PHP. Or I need to use regex, if yes which one?
Upvotes: 0
Views: 55
Reputation: 3360
use preg_split
$text = "Name: Long valueName2: Long loooooooong valueName3: short value";
$values = preg_split('/Name\d{0,1}\: /', $text, -1, PREG_SPLIT_NO_EMPTY);
You can then insert $values[0]
, $values[1]
, $values[2]
Upvotes: 2