• 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?

tenants

Well-known member
#1
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:

Code:
    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)
 

tenants

Well-known member
#2
okay, found it:

Code:
    public static function getTitleForUrl($title, $romanize = false)
    {
        if ($romanize)
        {
            $title = utf8_romanize(utf8_deaccent($title));
        }

        $title = strtr(
            $title,
            '`!"$%^&*()-+={}[]<>;:@#~,./?|' . "\r\n\t\\",
            '                            ' . '    '
        );

        $title = strtr($title, array('"' => '', "'" => ''));
        $title = preg_replace('/[ ]+/', '-', trim($title));

        return strtr($title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
    }