|Library sort titles function|
| 2:57 pm on Aug 4, 2009 (gmt 0)|
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)|
I am not too sure what you want to do but maybe you looking for something like trim or something along those lines.
| 2:16 am on Aug 5, 2009 (gmt 0)|
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)|
lol did you misspell my name on purpose? >_>
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)|
| 3:14 am on Aug 5, 2009 (gmt 0)|
$sorttitle=preg_replace("/^(The ¦A ¦An ¦)/",'',$title,1);