Jump to content

Renaming/Replacing Names


graham23s

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.