Removing prepositions [message #174262] |
Mon, 30 May 2011 01:32  |
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   |
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   |
 |
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   |
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   |
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 #174281 is a reply to message #174273] |
Mon, 30 May 2011 23:10   |
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 #174283 is a reply to message #174281] |
Tue, 31 May 2011 00:18   |
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 #174296 is a reply to message #174287] |
Tue, 31 May 2011 16:28  |
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).
|
|
|