Generate permalink to a blog post Hindi PHP -
i have 1 form in following inputs taken user:
- blog title
- blog description
- permalink access blog
i converting blog title lower case , replacing white spaces dash(-) , storing in permalink access blog
.
below code handle operation:
setlocale(lc_all, 'en_us.utf8'); function toascii($str, $replace=array(), $delimiter='-') { if( !empty($replace) ) { $str = str_replace((array)$replace, ' ', $str); } $clean = iconv('utf-8', 'ascii//translit', $str); $clean = preg_replace("/[^a-za-z0-9\/_|+ -]/", '', $clean); $clean = strtolower(trim($clean, '-')); $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean); return $clean; } $prmlkn = toascii($blog_headline, $replace=array(), $delimiter='-');
this code works fine till blog headline
in english. if user types in hindi
getting -
permalink means not recognizing hindi post values.
this happens because hindi uses extended character set in utf-8 , converting ascii provides latin characters, thus:
$str = "नमस्ते" $clean = iconv('utf-8', 'ascii//translit', $str); // clean empty string ""
according rfc3986
- characters
...
the abnf notation defines terminal values non-negative
integers (codepoints) based on us-ascii coded character set
[ascii]. because uri sequence of characters, must invert
relation in order understand uri syntax. therefore, theinteger values used abnf must mapped their
corresponding characters via us-ascii in order complete syntax rules.a uri composed limited set of characters consisting of
digits, letters, , few graphic symbols. reserved subset of
characters may used delimit syntax components within a
uri while remaining characters, including both unreserved set , reserved characters not acting delimiters, define each
component's identifying data.
you might better off using urlencode()
note might make ugly , long permalink
$str = "नमस्ते hello"; $clean = urlencode("$str"); printf("%s",$clean);
would result in valid ulgy:
%e0%a4%a8%e0%a4%ae%e0%a4%b8%e0%a5%8d%e0%a4%a4%e0%a5%87+hello
Comments
Post a Comment