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
Switch to threaded view of this topic Create a new topic Submit Reply
Removing prepositions [message #174262] Mon, 30 May 2011 01:32 Go to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
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
Re: Removing prepositions [message #174264 is a reply to message #174262] Mon, 30 May 2011 03:20 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
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
==================
Re: Removing prepositions [message #174265 is a reply to message #174262] Mon, 30 May 2011 04:06 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
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?
Re: Removing prepositions [message #174267 is a reply to message #174265] Mon, 30 May 2011 07:08 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> 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?

Well, that was just a quick bit of sample code. Since I'm converting
whitespaces to hyphens, it's a simple matter of removing "-a-" instead
of "a".

Jerry, I'm not entirely sure that you understand my point. Currently,
they would go to www.example.com/forum/, and if they wanted to go
directly to a thread, it would be something like:

www.example.com/forum/view/?msg=12345

I doubt that anyone is typing this in directly, but the link would
still work, so bookmarks would be fine. They would still go to
www.example.com/forum/; I'm just changing the link to the thread to:

www.example.com/forum/this-is-the-subject/12345/
Re: Removing prepositions [message #174273 is a reply to message #174267] Mon, 30 May 2011 13:00 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2011 3:08 AM, jwcarlton wrote:
>> 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?
>
> Well, that was just a quick bit of sample code. Since I'm converting
> whitespaces to hyphens, it's a simple matter of removing "-a-" instead
> of "a".
>
> Jerry, I'm not entirely sure that you understand my point. Currently,
> they would go to www.example.com/forum/, and if they wanted to go
> directly to a thread, it would be something like:
>
> www.example.com/forum/view/?msg=12345
>
> I doubt that anyone is typing this in directly, but the link would
> still work, so bookmarks would be fine. They would still go to
> www.example.com/forum/; I'm just changing the link to the thread to:
>
> www.example.com/forum/this-is-the-subject/12345/
>

Sure I understand your point, and my statement stands.

Additionally, why do you think this will do you any good? Search
engines are very good at finding sites who try to scam them for better
ratings.

Build a good site and it will get ranked high. Build a crappy site and
it will be ranked low. Try to scam the search engines and it won't be
ranked at all.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Removing prepositions [message #174280 is a reply to message #174273] Mon, 30 May 2011 22:13 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Additionally, why do you think this will do you any good?  Search
> engines are very good at finding sites who try to scam them for better
> ratings.


We were just discussing it on alt.www.webmaster, and all of the
replies seemed to think that it was a good idea.

http://groups.google.com/group/alt.www.webmaster/browse_frm/thread/ccd2acf8 26660517/c18d430d6a2451bf?lnk=raot#c18d430d6a2451bf
Re: Removing prepositions [message #174281 is a reply to message #174273] Mon, 30 May 2011 23:10 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Jerry Stuckle)

> On 5/30/2011 3:08 AM, jwcarlton wrote:
>>
>> Jerry, I'm not entirely sure that you understand my point. Currently,
>> they would go to www.example.com/forum/, and if they wanted to go
>> directly to a thread, it would be something like:
>>
>> www.example.com/forum/view/?msg=12345
>>
>> I doubt that anyone is typing this in directly, but the link would
>> still work, so bookmarks would be fine. They would still go to
>> www.example.com/forum/; I'm just changing the link to the thread to:
>>
>> www.example.com/forum/this-is-the-subject/12345/
>>
>
> Sure I understand your point

Obviously not.

> and my statement stands.

No. Neither does he change what users type in, nor does he touch their
texts, nor does he drive users away. He just generates URLs from the
submitted content like almost every blog software on this planet. He
just asked about how to optimize it.

If you upload a picture to an image hoster, would you get upset and be
driven away by the fact that a script on that site will automatically
generate a thumbnail from what you've uploaded?

> Additionally, why do you think this will do you any good?

User-friendly and readable/speaking URLs.

Compare these:

www.example.com/forum/?msg=12345
www.example.com/forum/this-here-is-the-text-about-that-something
www.example.com/forum/text-about-something

Obviously the last one would be preferred.

> Search
> engines are very good at finding sites who try to scam them for better
> ratings.

Who's trying to scam here?

> Build a good site and it will get ranked high. Build a crappy site and
> it will be ranked low. Try to scam the search engines and it won't be
> ranked at all.

A good site will be even better with good URLs. And all the OP wants is
to automatically create them - short and precise.

Micha
Re: Removing prepositions [message #174282 is a reply to message #174280] Tue, 31 May 2011 00:15 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2011 6:13 PM, jwcarlton wrote:
>> Additionally, why do you think this will do you any good? Search
>> engines are very good at finding sites who try to scam them for better
>> ratings.
>
>
> We were just discussing it on alt.www.webmaster, and all of the
> replies seemed to think that it was a good idea.
>
> http://groups.google.com/group/alt.www.webmaster/browse_frm/thread/ccd2acf8 26660517/c18d430d6a2451bf?lnk=raot#c18d430d6a2451bf

Interesting, because I'm on there also, and that's not at all what
people were saying.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Removing prepositions [message #174283 is a reply to message #174281] Tue, 31 May 2011 00:18 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2011 7:10 PM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 5/30/2011 3:08 AM, jwcarlton wrote:
>>>
>>> Jerry, I'm not entirely sure that you understand my point. Currently,
>>> they would go to www.example.com/forum/, and if they wanted to go
>>> directly to a thread, it would be something like:
>>>
>>> www.example.com/forum/view/?msg=12345
>>>
>>> I doubt that anyone is typing this in directly, but the link would
>>> still work, so bookmarks would be fine. They would still go to
>>> www.example.com/forum/; I'm just changing the link to the thread to:
>>>
>>> www.example.com/forum/this-is-the-subject/12345/
>>>
>>
>> Sure I understand your point
>
> Obviously not.
>

I understand EXACTLY what he's talking about.

>> and my statement stands.
>
> No. Neither does he change what users type in, nor does he touch their
> texts, nor does he drive users away. He just generates URLs from the
> submitted content like almost every blog software on this planet. He
> just asked about how to optimize it.
>
> If you upload a picture to an image hoster, would you get upset and be
> driven away by the fact that a script on that site will automatically
> generate a thumbnail from what you've uploaded?
>

He is changing what the user types in - and plugging it into urls. Not
at all like "almost every blog software on this planet".

>> Additionally, why do you think this will do you any good?
>
> User-friendly and readable/speaking URLs.
>
> Compare these:
>
> www.example.com/forum/?msg=12345
> www.example.com/forum/this-here-is-the-text-about-that-something
> www.example.com/forum/text-about-something
>
> Obviously the last one would be preferred.
>

But then that's not what he's trying to do, is he?

>> Search
>> engines are very good at finding sites who try to scam them for better
>> ratings.
>
> Who's trying to scam here?
>

He is - and obviously, you are if you support it.

>> Build a good site and it will get ranked high. Build a crappy site and
>> it will be ranked low. Try to scam the search engines and it won't be
>> ranked at all.
>
> A good site will be even better with good URLs. And all the OP wants is
> to automatically create them - short and precise.
>
> Micha

You really should learn something about SEO. In the meantime, I suggest
you stick to PHP coding.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Removing prepositions [message #174284 is a reply to message #174282] Tue, 31 May 2011 00:36 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Interesting, because I'm on there also, and that's not at all what
> people were saying.

Is Google Groups not showing me everything? I know that some people's
readers are set to ignore posts from Google Groups, but I don't know
if there's an issue the other way around. But I don't use NGs enough
to justify a separate program.

What I'm seeing is:

1. Me asking whether I should change the link (per above)

2. John Bokma giving advice on how to do it

3 & 4. Me replying

5. John Bokma saying that I should use a - instead of a _

6. You saying that I need to set Multiviews option in Apache.

7. Steve Sobol saying that query strings aren't SEO friendly, so I
should definitely make this change.
Re: Removing prepositions [message #174285 is a reply to message #174284] Tue, 31 May 2011 02:47 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2011 8:36 PM, jwcarlton wrote:
>> Interesting, because I'm on there also, and that's not at all what
>> people were saying.
>
> Is Google Groups not showing me everything? I know that some people's
> readers are set to ignore posts from Google Groups, but I don't know
> if there's an issue the other way around. But I don't use NGs enough
> to justify a separate program.
>

No, GG doesn't show everything, but it also shows a lot of spam.

> What I'm seeing is:
>
> 1. Me asking whether I should change the link (per above)
>
> 2. John Bokma giving advice on how to do it
>
> 3& 4. Me replying
>
> 5. John Bokma saying that I should use a - instead of a _
>
> 6. You saying that I need to set Multiviews option in Apache.
>
> 7. Steve Sobol saying that query strings aren't SEO friendly, so I
> should definitely make this change.

Which is NOT what they were talking about.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Removing prepositions [message #174286 is a reply to message #174285] Tue, 31 May 2011 03:35 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Which is NOT what they were talking about.

I hate to be obtuse, man, but no one in the thread (including you)
said that I should NOT do it. The purpose of the thread was to ask
whether I should bother, and the answers seemed to be affirmative.

I don't think that plugging the subject in to the link would be
considered spamming by search engines, though. So can you be more
specific on why you're now thinking it's a bad idea?
Re: Removing prepositions [message #174287 is a reply to message #174286] Tue, 31 May 2011 11:43 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2011 11:35 PM, jwcarlton wrote:
>> Which is NOT what they were talking about.
>
> I hate to be obtuse, man, but no one in the thread (including you)
> said that I should NOT do it. The purpose of the thread was to ask
> whether I should bother, and the answers seemed to be affirmative.
>
> I don't think that plugging the subject in to the link would be
> considered spamming by search engines, though. So can you be more
> specific on why you're now thinking it's a bad idea?

This has gone way off topic in this newsgroup. But you're talking
apples and oranges. What people told you there was something completely
different.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Removing prepositions [message #174296 is a reply to message #174287] Tue, 31 May 2011 16:28 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> This has gone way off topic in this newsgroup.  But you're talking
> apples and oranges.  What people told you there was something completely
> different.

I wasn't sure if we were going off topic or not. If you were trying to
say that removing prepositions from the subject string was a bad idea,
then it was an appropriate response to the thread.

Please feel free to offer any insight to the thread on
alt.www.webmaster. The subject is "Any value to changing variables to
a directory link?", and the last post is May 25 @ 12:34pm (I'm
assuming EST).
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Fri Nov 22 20:24:49 GMT 2024

Total time taken to generate the page: 0.06659 seconds