2016-07-24 6 views
2
私はPHPの機能もユニコード文字をサポートワードプレスなどのパーマリンクを作成したい

enter image description herePHPの関数は、ワードプレス

ハイテクなどのパーマリンクを作成します。現在、私は以下の関数をうまく使っていますが、Unicode文字はサポートしていません。

function create_slug_html($string, $ext='.html'){  
    $replace = '-';   
    $string=strtolower($string);  
    $string=trim($string); 
    //remove query string  
    if(preg_match("#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i",$string)){   
     $parsed_url = parse_url($string);   
     $string = $parsed_url['host'].' '.$parsed_url['path'];   
     //if want to add scheme eg. http, https than uncomment next line   
     //$string = $parsed_url['scheme'].' '.$string;  
    }  
    //replace/and . with white space  
    $string = preg_replace("/[\/\.]/", " ", $string);  
    $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);  
    //remove multiple dashes or whitespaces  
    $string = preg_replace("/[\s-]+/", " ", $string);  
    //convert whitespaces and underscore to $replace  
    $string = preg_replace("/[\s_]/", $replace, $string);  
    //limit the slug size  
    $string = substr($string, 0, 100);  
    //slug is generated  
    return ($ext) ? $string.$ext : $string; 

}

インスタンスがmb_ereg_replace代わりのにpreg_replaceを使用するためにあなたは、マルチバイトサポートを提供するためにfunctions prefixed with mbを使用することが私にどんな変化や新しいコード

答えて

1

を示唆しています。その他には、mb_substrおよびmb_strtolowerが含まれます。

ただし、デフォルトのエンコーディングはUnicodeではなくUTF-8であるため、エンコーディングを指定する必要があります。これはmb_regex_encodingを使用して行われます。