HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Any functions built-in to slugify a string?

Does Vanilla currently have a function built-in to convert a string to a slug/URL code? Looking for a formatter on the PHP side, not the existing one written in JS for category settings.

Add Pages to Vanilla with the Basic Pages app

Comments

  • R_JR_J Admin

    Like slugify() in functions.general.php? 😉

  • x00x00 MVP
    edited May 2019

    or

    Gdn_Format::url()

    grep is your friend.

  • edited May 2019

    I was thinking of importing a library such as Slug Generator for an addon, but those would be quite useful. Thank you both for pointing those out! Do either of those algorithms handle special/international characters (Cyrillic, etc) well?

    Add Pages to Vanilla with the Basic Pages app

  • R_JR_J Admin

    slugify uses iconv to "transliterate"

           // transliterate
           $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
    
  • charrondevcharrondev Vanilla Staff

    Gdn_Format::url() just replaces unicode characters with hyphens.

  • edited May 2019

    I'll go with slugify() for this project. It doesn't seem to handle special inputs such as "富士山", which outputs "n-a" (wherein the result came out empty) instead of "fu-shi-shan", for example, but I can always use a library to handle this when the need arises. Thanks for the replies! 😀

    Add Pages to Vanilla with the Basic Pages app

Sign In or Register to comment.