3

I am using following slugify method,in my local dev its working fine,but in my production server(CentOs) and the PCRE UTF8 supported but "No Unicode properties support".

function slugify($text)
{
    // replace non letter or digits by -
    $text = preg_replace('~[^\\pL\d]+~u', '-', $text);

    // trim
    $text = trim($text, '-');

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

    // lowercase
    $text = strtolower($text);

    // remove unwanted characters
    $text = preg_replace('~[^-\w]+~', '', $text);

    if (empty($text)) {
        return 'n-a';
    }
    return $text;
}

And preg_replace is not working there,is there any method that can work as preg_replace,or any slugify muthod that can work as the above function.

Thanks in advance.

8
  • Why do you need UTF8 support if you have already made a translitertion to us-ascii? Define "not working" Commented Oct 1, 2011 at 7:35
  • Why has this been voted down...? Commented Oct 1, 2011 at 8:06
  • I need unicode properties support actually Commented Oct 1, 2011 at 8:11
  • 2
    If you need unicode properties support, you need to enable it. If you are on a shared host, your hosting provider should do that for you. I can't think of anything else other than having some tables to replace characters for the specific language to their respective non-unicode letters. Like $trans = array('ä' => 'a', 'å' => 'a', 'ö' => 'o'); $slug = strtr($string, $trans);. After the translations have been done, discard anything other than A-Za-z0-9. Commented Oct 1, 2011 at 8:19
  • 1
    Actually what is not working with your code? How does the "not working" look like? What do you want your slugify method to do? Just remove all characters that are not part of the us-ascii charset? And you have two regexes, which one fails? Are you getting an error message? Commented Oct 1, 2011 at 9:09

1 Answer 1

1

This sounds like the same issue described here: http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/. I've run into it before myself, and that link is how I fixed it (or rather, how our sysadmin fixed it).

Essentially, the \pL in the first regex will not run or compile if you do not have "Unicode properties support".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.