Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1923

Re: Removing prepositions

From richard <member@newsguy.com>
Newsgroups comp.lang.php
Subject Re: Removing prepositions
Date 2011-05-29 21:06 -0700
Organization NewsGuy - Unlimited Usenet $19.95
Message-ID <dhvm1y4hsyvo$.dlg@evanplatt.sux> (permalink)
References <afc0d014-f32b-4dc9-9f55-4fd156f2779a@c26g2000vbq.googlegroups.com>

Show all headers | View raw


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?

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-29 18:32 -0700
  Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-29 23:20 -0400
  Re: Removing prepositions richard <member@newsguy.com> - 2011-05-29 21:06 -0700
    Re: Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-30 00:08 -0700
      Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-30 09:00 -0400
        Re: Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-30 15:13 -0700
          Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-30 20:15 -0400
            Re: Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-30 17:36 -0700
              Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-30 22:47 -0400
                Re: Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-30 20:35 -0700
                Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-31 07:43 -0400
                Re: Removing prepositions jwcarlton <jwcarlton@gmail.com> - 2011-05-31 09:28 -0700
        Re: Removing prepositions Michael Fesser <netizen@gmx.de> - 2011-05-31 01:10 +0200
          Re: Removing prepositions Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-30 20:18 -0400

csiph-web