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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.