9 Replies Latest reply on Feb 21, 2012 2:16 PM by ccrumley

    Creating SEO-Friendly URL's

    ccrumley

      Title

      Creating SEO-Friendly URL's

      Post

       

      We are currently using this function to clean a string and make it ready for use as an SEO-friendly URL

      It replaces spaces, parentheses, commas, semicolons, single quotes, double quotes, %'s, spaces and equals signs with hyphens. i'm sure this can be cleaned up- but i'm not familiar with regex as it works in FM...

      Substitute (description ; ["/" ; "-"] ; [" " ; "-"] ; ["&" ; "-"] ;["@ " ; "-"] ;["'" ; "-"] ;["\" " ; "-inch-"] ;["(" ; "-"] ; [")" ; "-"] ;["%" ; "-"] ;["," ; "-"];["#" ; "-"];[";" ; "-"];["=" ; "-"])

      we keep getting unexpected results with some spaces and quotes not being replaced - can anyone see room for improvement?

        • 1. Re: Creating SEO-Friendly URL's
          philmodjunk

          Straight quotes and smart (curly) quotes are different characters so your substitute function may be replacing one type and not the other. There is also more than one character that can look like a space so you may have other characters than a simple space in your text.

          • 2. Re: Creating SEO-Friendly URL's
            ccrumley

            maybe try to check for ascii characters?

            ' = the single quote( ' )...

            so can i run the Substitute() function and check against ascii values?

            Substitute (description ; ["'" ; "-"]) etc...

            • 3. Re: Creating SEO-Friendly URL's
              philmodjunk

              Try using the Char function. This requires using the unicode for the character instead of ascii. You can also copy the characters that are making it through, pasting it into a text field and use Code ( textfield ) to discover the code.

              You may also want to experiment with the Filter command to filter out all characters but a list of accepted characters.

              • 4. Re: Creating SEO-Friendly URL's
                ccrumley

                Filter's no good here because i need to replace the spaces in a string with dashes- for readability and SEO

                i.e "This is a product 3" wide" will become 

                "This-is-a-product-3-wide" etc.

                • 5. Re: Creating SEO-Friendly URL's
                  ccrumley

                  Substitute (description ; ["/" ; "-"] ; [" " ; "-"] ; ["&" ; "-"] ;["@ " ; "-"] ;["'" ; "-"] ;["\" " ; "-inch-"] ;["(" ; "-"] ; [")" ; "-"] ;["%" ; "-"] ;["," ; "-"];["#" ; "-"];[";" ; "-"];["=" ; "-"];["'" ; "-"];[""" ; "-"];[Char(32) ; "-"];[Char(34) ; "-inch-"])

                   

                  good call on the Code() -> Char() trick to find the character value- it helped alot. Decided to replace the phrase "3"" to "3-inch-" for readabilities sake.

                  posting this solution for future reference. thanks Phil.

                  • 6. Re: Creating SEO-Friendly URL's
                    philmodjunk

                    Filter's no good here because i need to replace the spaces in a string with dashes-

                    Not what I had in mind. Wink

                    I'm suggesting you use Filter to omit the unusual extra characters nested inside your substitute function to replace the conventional characters with dashes. This gives you a way to deal with any other non printing characters that may show up in the future instead of having to continually update your substitute function to handle more and more characters.

                    • 7. Re: Creating SEO-Friendly URL's
                      ccrumley

                      i think filter() will cause more problems though- it will remove the specified characters from a string rather than replacing them.

                      if i filter the unusual spaces from this string "this is a string" - it will just become "thisisastring" right? 

                      in PHP i can do this to turn any non-alphanumeric character into a hyphen

                      $cleanString=ereg_replace("[^A-Za-z0-9]","-",$dirtyString)
                      • 8. Re: Creating SEO-Friendly URL's
                        philmodjunk

                        Yep, but once you've accounted for all the "most likely" stuff in your substitute function, it might serve as an "insurance policy" to protect you from producing a link that won't work. Hmmm, that means I'd have to reverse things though, and put the substitute function inside the filter function so that identified characters get substituted before the filter function screens out any other characters.

                        You could even use filter as a "warning flag". After substituting, if the length of the filtered text does not equal the length of the unfiltered text, you've got one or more characters present that your substitute function failed to deal with.

                        the PHP example is interesting. I can imagine a pretty straight forward recursive custom function that could be creatd with FileMaker Advanced that would do the same--replacing all characters not part of a specified range of values with a specified character. There are web sites where custome functions are shared and a search of them might locate one already written that does this for you.

                        • 9. Re: Creating SEO-Friendly URL's
                          ccrumley

                          i'll come back an add it to this thread if i come across one, thanks for thinking through this one