Page 1 of 1

How do i create SEO urls by removing prepositions

Posted: Fri Nov 27, 2009 7:32 am
by huntsvillepr
I am trying to create some seo friendly url by removing all prepositions in the url. I am also removing spaces and replacing with dashes.

The problem is when i use the str_replace function it sometimes remove letters in other words.

For example, in a title like this: UnitedHealthcare To Offer Seniors Fitness Program Through A Insurance plan

The title url is rewritten UnitedHealthcare-fer Seniors-Fitness-Program-Through-A-surance-plan

It removes the OF in offer and the IN in insurance

Is there another function or another way to remove only prepositions by themselves and not when their instance is found in a word?

thanks. Here is the code i am currently using

$result = ("SELECT id, date, title FROM dir_news ORDER BY id DESC LIMIT 0, 20 ");

$res = mysql_query ($result);

while ($row = mysql_fetch_array($res)) {
$title = ucwords($row ['title']);
$id = $row ['id'];
$date = $row['date'];

$preposition=array(",", "'", "A", "And", "About", "Above", "Across", "After", "Against", "Along", "Among", "Around", "At", "Before", "Behind", "Below", "Beneath", "Beside", "Between", "Beyond", "But", "By", "Despite", "Down", "During", "Except", "For", "From", "In", "Inside", "Into", "Like", "Near", "Of", "Off", "On", "Onto", "Out", "Outside", "Over", "Past", "Since", "Through", "Throughout", "Till", "To", "Toward", "Under", "Underneath", "Until", "Up", "Upon", "With", "Within", "Without");
$replace=array('');
$link = str_replace($preposition, $replace, $title);

$link = str_replace(' ', '-', $link);
$link = str_replace('---', '-', $link);
$link = str_replace('--', '-', $link);

echo '<a href="http://www.allinsurancecoverage.com/'.$link .'-n'. $id . '.html">' . $title . ' </a> ' . $date. '';
echo '<p>';