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
Re: Removing prepositions [message #174265 is a reply to message #174262] Mon, 30 May 2011 04:06 Go to previous messageGo to previous message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma:
Senior Member
On Sun, 29 May 2011 18:32:30 -0700 (PDT), jwcarlton wrote:

> 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

Problem is, many common words use those prepositions even though they are
not.

In your example, eliminating "a" would change "about" to "bout".
"reply" becomes "ply".
So why bother?
[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: Sun Nov 24 23:48:06 GMT 2024

Total time taken to generate the page: 0.05046 seconds