I am creating this app using laravel. It requires to have Japanese slugs because almost all of the content is in Japanese language. I tried to use several packages but none of them provide good support to Japanese language. So, I am trying to create it myself. In order to have proper slug I am trying to achieve these..
- strips HTML & PHP
- strips special chars
- converts all characters to lowercaps
- replaces whitespaces, underscores and periods by hyphens/dashes
- reduces multiple consecutive dashes to one
To strips special characters I thought of using preg_replace() but the problem is it is also removing the Japanese letters. I tried encoding it to utf8 but no solution. Now, I want to create the function that will replace all the characters not required in a slug.
$slug = iconv("UTF-8", "ISO-8859-1//TRANSLIT", utf8_encode(strtolower((str_replace(' ', '-', $title)))));
So, I want a list/array of characters that must be replaced. I have listed these.If you think any other characters must be considered please help?
array("~", "!", "@","#","$","%","^","&","*","(",")","_","+","}","{","[","]",".",",","\\","/","|");
If you have any alternative solution to this I would love to use that.