PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jonah Bron
DevNet Master
Posts: 2764 Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California
Post
by Jonah Bron » Fri Feb 18, 2011 7:46 pm
Aha! Good catch, Info. Try this:
Code: Select all
<?php
$lines = file('c:\dwagent\clients.dwa');
$delimiter = "]";
function sortByValue($value1, $value2) {
echo strcmp($value1[1], $value2[1]);
}
foreach ($lines as $line_num => $line) {
$parameters = array();
$splitcontents = explode($delimiter, $line);
$counter = 0;
foreach ( $splitcontents as $color ) {
$counter++;
if ($counter == 1){
$parameters[] = array('Name', $color);
} elseif ($counter == 3){
$parameters[] = array('SQL', $color);
} elseif ($counter == 5){
$parameters[] = array('WEB', $color);
}
}
usort($parameters, 'sortByValue');
foreach ($parameters as $parameter) {
echo '<b>' . $parameter[0] . ': </b> ' . $parameter[1] . ' <br />';
}
}
?>
AdrenalineSeed
Forum Newbie
Posts: 24 Joined: Sat Oct 09, 2010 5:54 pm
Post
by AdrenalineSeed » Tue Feb 22, 2011 5:25 pm
Ok that took out the big space, lol. I don't see any extra lines in the file at the top.
I can't post the file but here is sort of what it looks like
Client1]\\path]server]db]host]service5
Client2]\\path2]server2]db2]host4]service
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Tue Feb 22, 2011 6:34 pm
Code: Select all
$parameters = array();
if (($handle = fopen("c:\dwagent\clients.dwa", "r")) !== FALSE)
{
while (($csv = fgetcsv($handle, 1000, "]")) !== FALSE)
{
$parameters[] = array
(
'Name' => $csv[1],
'SQL' => $csv[3],
'WEB' => $csv[5],
);
}
}
function sortByName($value1, $value2)
{
return strcmp($value1['Name'], $value2['Name']);
}
usort($parameters, 'sortByName');
foreach ($parameters as $parameter)
{
echo $parameter['Name'] . ': ' . $parameter['SQL'] . ' : ' . $parameter['WEB'];
}
PS:
Code: Select all
echo strcmp($value1[1], $value2[1]);
There are 10 types of people in this world, those who understand binary and those who don't
AdrenalineSeed
Forum Newbie
Posts: 24 Joined: Sat Oct 09, 2010 5:54 pm
Post
by AdrenalineSeed » Wed Feb 23, 2011 11:07 am
Vlad! It worked! Thanks, and thanks everyone for your help on this. A round on me