I have a string such as this :
$postings = "1 ADSR|
1 Armoured Field Ambulance|
94 Locating Regiment|
97 Gurkha Infantry Brigade|
9th (The Queens Royal) Lancers|
10 Fd Wksp REME|
AAC Arborfield|
ACIO|
";
This string is held in its own file called postings.php and 'required' by the scripts in which it is used (it is also a lot longer than this but the same format)
It forms a drop down box in a form that allows ex-forces members to select the postings that they were sent to.
They can also email me with postings that aren't on the list. So.. here's the problem I have...
I need to write a script that will allow me to open the file (ie. postings.php), add a 'posting', re-sort them into alphabetical order and then re-write the file.
Any got any ideas ??
I know I can open the file with :
if (file_exists("postings.php" {
$file_contents = fopen("path/to/file.txt", "r+"
}
else {
echo "files gone awol !";
}
... but as for adding the new postings and then alphabetically sorting them and writing them back to the file.. well, to say I was a bit stuck would be an understatement.
A big thanks for any help you can give me.
Cheers
JT I don't make mistakes, I'm merely beta-testing life.
$postings = "1 ADSR|
1 Armoured Field Ambulance|
94 Locating Regiment|
97 Gurkha Infantry Brigade|
9th (The Queens Royal) Lancers|
10 Fd Wksp REME|
AAC Arborfield|
ACIO|
";
This string is held in its own file called postings.php and 'required' by the scripts in which it is used (it is also a lot longer than this but the same format)
It forms a drop down box in a form that allows ex-forces members to select the postings that they were sent to.
They can also email me with postings that aren't on the list. So.. here's the problem I have...
I need to write a script that will allow me to open the file (ie. postings.php), add a 'posting', re-sort them into alphabetical order and then re-write the file.
Any got any ideas ??
I know I can open the file with :
if (file_exists("postings.php" {
$file_contents = fopen("path/to/file.txt", "r+"
}
else {
echo "files gone awol !";
}
... but as for adding the new postings and then alphabetically sorting them and writing them back to the file.. well, to say I was a bit stuck would be an understatement.
A big thanks for any help you can give me.
Cheers
JT I don't make mistakes, I'm merely beta-testing life.