homepage Welcome to WebmasterWorld Guest from 54.225.24.227
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Library sort titles function
ianevans




msg:3965389
 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! :)

 

messageboy




msg:3965797
 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.

[us2.php.net...]

eelixduppy




msg:3965805
 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]

messageboy




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

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]

eelixduppy




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

honest typo

ianevans




msg:3965829
 3:14 am on Aug 5, 2009 (gmt 0)

This works:

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved