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 #174264 is a reply to message #174262] Mon, 30 May 2011 03:20 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 5/29/2011 9:32 PM, 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

Don't even try. Users will get very upset when you change that they
type in. It's their text, and their responsibility to determine what
they want in there - not yours.

Of course, if you want to look for more ways to drive people away from
your site, this is a good start.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Wed Nov 27 00:34:31 GMT 2024

Total time taken to generate the page: 0.05077 seconds