1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

titles into urls, regex that xenforo uses?

Discussion in 'XenForo Development Discussions' started by tenants, Sep 24, 2011.

  1. tenants

    tenants Well-Known Member

    What regex does xenforo use to covert the thread titles into the section used in urls,

    I thought about using my own "hack", but I dont like it and I want to be consistent

    my own hack:

        public function intoUrl($title){
            $url =  preg_replace("/[^0-9A-Za-z]/","-", $title);
            $url = str_replace("--", "-",$url);
            $url = str_replace("--", "-",$url); // this is really horrible, using the same str_replace, but clears up any odd dashes ---
            return $url;
    (then after this, obviously add the .node_id)
  2. tenants

    tenants Well-Known Member

    okay, found it:

        public static function getTitleForUrl($title, $romanize = false)
            if ($romanize)
                $title = utf8_romanize(utf8_deaccent($title));
            $title = strtr(
                '`!"$%^&*()-+={}[]<>;:@#~,./?|' . "\r\n\t\\",
                '                            ' . '    '
            $title = strtr($title, array('"' => '', "'" => ''));
            $title = preg_replace('/[ ]+/', '-', trim($title));
            return strtr($title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');

Share This Page