graham23s Posted August 20, 2010 Share Posted August 20, 2010 Hi Guys, I use this function to generate seo friendly names for my products once pulled from the database: function generate_seo_friendly_links($pNM, $pID) { $replacedNM = str_replace(" ", "-", $pNM); $replacedNM = rtrim($replacedNM); $brandNewSEOFriendlyURL = "<a href='$replacedNM-$pID.html'>$pNM</a>"; return $brandNewSEOFriendlyURL; } This works great, the only thing is say a product is stored in the database like: product name it would then be converted to: product-name.html if for example theres 2 spaces: product name it would then be converted to: product--name.html with the 2 "--" so for every space it finds we replace with a "-" etc is there a way i could ignore more than 1 space and always have it like product-name-here.html so the names are more uniformed, i can't think of a way to do it. any help would be appreciated thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/211314-renamingreplacing-names/ Share on other sites More sharing options...
ram4nd Posted August 20, 2010 Share Posted August 20, 2010 ise "while" loop and" str_replace" Link to comment https://forums.phpfreaks.com/topic/211314-renamingreplacing-names/#findComment-1101800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.