FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Removing prepositions
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Removing prepositions [message #174262] Mon, 30 May 2011 01:32 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
I'm pretty sure that the answer to this is "no", but I thought I'd
ask, anyway.

Is there a better way to remove prepositions from a string than
putting them all in an array manually, then using str_ireplace()?

Here's what I'm currently doing, but I'm looking for a way to speed it
up:

// roughly 200 words and phrases here
$prepositions = array("a", "an", "as", "at", ...);

// remove non alphanumeric
$string = preg_replace("/[^a-zA-Z0-9\s]/", "", $string);

// convert \s to -
$string = preg_replace("/ /", "-", $string);

// remove prepositions
$string = str_ireplace($prepositions, "", $string);

// shorten $string
if (strlen($string) > 50)
$string = substr($string, 0, 50);

If it matters, I'm using this in a message board, and I'm plugging the
subject into the link to the thread (for search engines). Since I'm
limiting the length to 50 characters, I want to make sure that as many
keywords as possible are in there.

TIA,

Jason
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP Extension Won't Install
Next Topic: PHP Programmers for PHP Web Development
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 22:04:19 GMT 2024

Total time taken to generate the page: 0.04037 seconds