here's your script,

<?
$mem = "The Childhood
A Man called lallous
The Long kiss good night
Abbey Road
Dark Side Of the Moon
The Final Cut
The Zombie
A Hard Days Night
Kill 'em All
The Wall";

$mem = split("\n", $mem);
$arr1 = array();

for ($i=0;$i<count($mem);$i++)
{
  $line = trim($mem[$i]);
  $prefix = "";
  $affix = $line;
  if (preg_match("/^(the |a )(.+)$/i", $line, $matches))
  {
    $prefix = $matches[1];
    $affix  = $matches[2];
  }
  $arr1[$affix] = $prefix;
}
ksort($arr1);
$arr2 = array();
while (list($key, $val) = each($arr1))
{
  $arr2[] = "$val$key";
}
var_dump($arr2);
?>


"Dotan Cohen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm trying to sort a listing of albums alphabetically
> for LyricsList.com, the problem is that I want the
> initial 'The' and 'A' in some albums (A Hard Days
> Night, The Wall) to be ignored. So that the list will
> look like:
>
> Abbey Road
> Dark Side Of the Moon
> The Final Cut
> A Hard Days Night
> Kill 'em All
> The Wall
>
> ABC order, 'A' and 'The' negated. The info comes from
> a database, in three calls:
>
> // call albums that begin with letter $letter
> $query = "SELECT * FROM albums WHERE album LIKE
> '$letter%' ORDER BY album";
> $result = mysql_query($query) or die(mysql_error());
>
> // call albums that begin with letter A
> $query_a = "SELECT * FROM albums WHERE album LIKE 'a'
> ORDER BY album";
> $result_a = mysql_query($query_a) or
> die(mysql_error());
>
> // call albums that begin with letter T
> $query_t = "SELECT * FROM albums WHERE album LIKE 't'
> ORDER BY album";
> $result_t = mysql_query($query_t) or
> die(mysql_error());
>
> So I need to get just the albums from $result_t that
> begin with 'The ' (easy regex) and from $result_a that
> begin with 'A ' (easy regex), but puting the three of
> them in order is proving beyond my skill.
>
> Thanks in advance for any advise.
>
> Dotan Cohen
>
>
> __________________________________________________
> Terrorist Attacks on U.S. - How can you help?
> Donate cash, emergency relief information
> http://dailynews.yahoo.com/fc/US/Emergency_Information/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to