I have an NLIST of users that I need to reformat into a csv file. I can do this with regular expressions in, say, Edit Plus, but I want to be able to do it in PHP. Here is a sample of the file I need to reformat:
Input:
Object Class: User
Current context: hoff.Sydney.Australia.PONedlloyd
User: UNIX Service Handler
Last Name: NetDB/NDS
User: guest
Last Name: Guest
Given Name: Guest
User: NetShield_HUB_SERVER
Last Name: NetShield
A total of 3 User objects was found in this context.
Object Class: User
Current context: TTT.hoff.Sydney.Australia.PONedlloyd
User: hpanamba
Last Name: Panambalana
Given Name: Harin
One User object was found in this context.
Object Class: User
Current context: F4BusSup.hoff.Sydney.Australia.PONedlloyd
User: ncamero
Last Name: Cameron
Given Name: Nikki
User: suchiza
Last Name: Uchizawa
Given Name: Sayaka
User: akinoi
Last Name: Kinoi
Given Name: Aya
Desired Output:
User, akinoi, Last Name, Kinoi, Given Name, Aya, F4BusSup.hoff.Sydney
User, suchiza, Last Name, Uchizawa, Given Name, Sayaka, F4BusSup.hoff.Sydney
User, ncamero, Last Name, Cameron, Given Name, Nikki, F4BusSup.hoff.Sydney
Am very new to regular expressions, but was using the following to get the text into the desired format
replace Object. with nothing
replace Current. with nothing
replace One User. with nothing
replace A Total. with nothing
replace \t.* with nothing
replace \nGiven[\n\n] with ": Given "
replace \nLast[\n\n] with ": Last "
replace \n with nothing
replace : with ,
Replacing the Given and Last parts are what sucks it up a line, for some reason I had to search for and then replace the whole word, because if I didn't search for the whole word, for some reason the first letter of the word would also be selected to be replaced...
Have tried a whole bunch of different ways to do this in php, as i need an automated script to do it, but for the life of me I can't get it to replace new lines to format the text as desired.
Anyone got any advice? Should i be using ereg functions or str functions? ATM i just have a whole bunch of eregs running, and have tried accessing the file line by line, as an array, line by line in an array, 2 lines at a time, 2 lines from an array at a time etc etc etc!
please help!