I'm working on generating SEO friendly URLs from data taken from a database. I've been successful for the most part. The only issue I'm having is when I stripped the spaces and made them dashes, I lose the data being pulled from the database. If I leave the spaces in there (ex. www.test.com/test/this is a sample article/) it works fine. When I replace the spaces with dashes I lose the data that supposed to be displayed on the page. It also works if I change the spaces to '+' signs. I'd like to have '-' or '_' though.
Query code:
$query = "Select * From Family Where $View = View order by Name";
This is the link code.
echo '<a href="/family/';
$product_title_url = gen_seo_friendly_titles($row['Name']);
echo $product_title_url;
echo '/">';
This is the code to strip out spaces etc.
function gen_seo_friendly_titles($title) {
$replace_what = array(' ', ' - ', ' ', ', ', ',');
$replace_with = array(' ', '-', '_', ',', '-');
$title = strtolower($title);
$title = str_replace($replace_what, $replace_with, $title);
return $title;
}