You are here:  » Remove accent from URL

Support Forum



Remove accent from URL

Submitted by Jibus on Sun, 2010-09-19 14:55 in

Hi David,

First of all, i would like to say that your script is excellent and thanks to the forum support, i found many "tricks" in order to improve the visibilty of my website.

Unfortunalty, i didn't find a post about accent in url.

My aim is to remove accent from the url for search engine.

This the type of code, i want to add:

$accent ="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ";
$noAccent="AAAAAAACEEEEIIIIDNOOOOOOUUUUYBsaaaaaaaceeeeiiiidnoooooouuuyyby";

but i don't know where to put it.

I found a post how to put the url in lowercase but not about accent (in my case, it's french accent)

Thanks for your next answer.

Submitted by support on Sun, 2010-09-19 15:22

Hi Jibus,

Thanks for your comment.

What you want to do is apply the conversion as an str_replace() within the import record handler function in includes/admin.php. In that file, look for the following code beginning at line 271:

    /* create normalised version of product name for use in URLs */
    $normalisedName = tapestry_normalise($importRecord["name"]);

...and REPLACE that with:

    /* create normalised version of product name for use in URLs */
    $normalisedName = tapestry_normalise($importRecord["name"]);
    global $accent;
    global $noAccent;
    if (!is_array($accent))
    {
    $accent = array("À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É",
                      "Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó",
                      "Ô","Õ","Ö","Ø","Ù","Ú","Û","Ü","Ý","Þ",
                      "ß","à","á","â","ã","ä","å","æ","ç","è",
                      "é","ê","ë","ì","í","î","ï","ð","ñ","ò",
                      "ó","ô","õ","ö","ø","ù","ú","û","ý","ý",
                      "þ","ÿ");
    $noAccent = array("A","A","A","A","A","A","A","C","E","E",
                      "E","E","I","I","I","I","D","N","O","O",
                      "O","O","O","O","U","U","U","U","Y","B",
                      "s","a","a","a","a","a","a","a","c","e",
                      "e","e","e","i","i","i","i","d","n","o",
                      "o","o","o","o","o","u","u","u","y","y",
                      "b","y");
    }
    $normalisedName = str_replace($accent,$noAccent,$normalisedName);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Jibus on Sun, 2010-09-19 16:43

Thanks for your quick answer !

After adding the code below, the "wrong" letter is changed but i have a weird character instead

I use utf-8.

Any idea ?

Jibus

Submitted by support on Sun, 2010-09-19 16:52

Hi,

Make sure that your editor is working in UTF-8 before copying and pasting the code into it. This website is running in UTF-8, so the copy / paste operation should work fine, but your text editor may default to a different encoding (e.g. ISO-8859-1). Try this procedure:

1) Open the original (unmodified) includes/admin.php in your text editor

2) Use your editor's File > Save As... menu option, and look for a character encoding setting, and choose "UTF-8 NO BOM" (or similar setting). BOM means "Byte Order Marking", which can cause problems in files uploaded to a web server as the BOM characters can be output before the script intends any output to begin.

3) Copy the above code, and then Paste into the file at the appropriate position.

4) Save, and your file should then be saved as UTF-8 with No BOM and should then work as expected...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Jibus on Sun, 2010-09-19 17:06

It works :)

Thanks you !