Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: coopster & jatar k

Library sort titles function

   
2:57 pm on Aug 4, 2009 (gmt 0)

10+ Year Member



This is going to be one of those issues that will have me creating a head shaped dent on table in front of me, but I was driven out of my apartment by construction this morning and haven't had sufficient coffee.

What's the most efficient way to create a string into a library sorted version? That is dropping any "An ", "A " or "The " e.g. "The Godfather" becomes "Godfather".

In mysql I do the following:

SELECT apnumber, aptitle, IF( aptitle LIKE 'The %', SUBSTRING( aptitle, 5 ) , IF( aptitle LIKE 'A %', SUBSTRING( aptitle, 3 ) , IF( aptitle LIKE 'An %', SUBSTRING( aptitle, 4 ) , aptitle ) ) ) AS sorttitle etc...

I'd like to be able to handle this before mysql but my coffee/sleep deprived brain is making this too hard! :)

2:09 am on Aug 5, 2009 (gmt 0)

5+ Year Member



I am not too sure what you want to do but maybe you looking for something like trim or something along those lines.

[us2.php.net...]

2:16 am on Aug 5, 2009 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Sounds like something that is a little too intense to keep in just the MySQL query. I would do the select normally, then run a str_replace [php.net]() on an array of all words you want to get rid of, then use messageboy's trim [php.net]() function to get rid of any unwanted whitespace.

See what you can come up with.

[edited by: eelixduppy at 2:41 am (utc) on Aug. 5, 2009]

2:19 am on Aug 5, 2009 (gmt 0)

5+ Year Member



lol did you misspell my name on purpose? >_>

Edit:

I thought so. :P

[edited by: messageboy at 2:43 am (utc) on Aug. 5, 2009]

2:42 am on Aug 5, 2009 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



honest typo
3:14 am on Aug 5, 2009 (gmt 0)

10+ Year Member



This works:

$sorttitle=preg_replace("/^(The ¦A ¦An ¦)/",'',$title,1);

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month