Any functions built-in to slugify a string?

ShadowdareShadowdare Moderator

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 Cheerleader & Troubleshooter Munich Moderator

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


    Shadowdare
  • x00x00 MVP
    edited May 13

    or

    Gdn_Format::url()

    grep is your friend.

    Shadowdare
  • ShadowdareShadowdare Moderator
    edited May 13

    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 Cheerleader & Troubleshooter Munich Moderator

    slugify uses iconv to "transliterate"

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


    Shadowdare
  • charrondevcharrondev Application Developer (PHP, JS) Montreal Vanilla Staff

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

    Shadowdare
  • ShadowdareShadowdare Moderator
    edited May 13

    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.