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


Groups > comp.lang.php > #1922

Re: Removing prepositions

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Removing prepositions
Date 2011-05-29 23:20 -0400
Organization A noiseless patient Spider
Message-ID <irv2dr$jf7$1@dont-email.me> (permalink)
References <afc0d014-f32b-4dc9-9f55-4fd156f2779a@c26g2000vbq.googlegroups.com>

Show all headers | View raw


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@attglobal.net
==================

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