This extension is used to make the url more clean, change the blank to dash, change the un-ascii code to ascii, such as Œ to OE, À to A and so on. Remove the unsafe symbols such as &%$#@
Requirements ¶
Yii 1.0 or above
Usage ¶
Download the code, and locate it in protected/components
test in your controller,
echo UrlTransliterate::cleanString("我爱 中文!");
Feedback
Hey,
nice class :) I have written such a component too but not that complete. Here some ideas:
$ignoreWords: Perhaps the user of the component wants to modify this, especially because of other languages. And perhaps it would be better that there is no default value.
Modify your punctuationChars() method like this:
$punctuation = array( 'double_quotes' => '"', 'quotes' => "'", 'backtick' => '`', [...] );
So you have to adjust your loop in cleanString().
Feedback
Nice one. Why Russian (Cyrillic) letters are translated to uppercased English letters? Should be lowercased.
Feedback
@g3ck0
Thank you for your suggestion. I have upgraded the code except the point 1: $ignoreWords. Because i think that that if the user ignore some words include the un-ASCII characters, then this class will lost its function, right?
Just feel free to have a discussion. :)
@samdark
Thank you for your testing, but i didn't find the error, here is the test code. (Please forgive me the words i just copy from the yii forum, and i don't know what does that mean :p )
echo UrlTransliterate::cleanString( 'Я вот капчу определил в контроллере, вывел где нужно. Но все примеры основаны на валидаторе форм, а я его не использую... Подскажите где взять значение капчи чтобы самому в контроллере сделать проверку.' );
Here is the result:
ya-vot-kapchu-opredelil-v-kontrollere-vyvel-gde-nuzhno-no-vse-primery-osnovany-na-validatore-form-a-ya-ego-ne-ispolzuyu-podskazhite-gde-vzyat-znachenie-kapchi-chtoby-samomu-v-kontrollere-sdelat-proverku
Thanks
My clients have multilingual websites so this comes in very handy.
This extension is very good for multilingual sites
I used this code before: (/protected/components/UrlGenerator.php)
class UrlGenerator { /** * create url friendly text from free text * @param string $str free text * @return string url friendly text */ public static function encodeStringToURL($str) { $search = array('ö','ó','ü','ő','ú','é','á','ű','í', 'Ö','Ü','Ó','Ő','Ú','É','Á','Ű','Í', ' ', 'ß', 'ä', 'Ä', '.'); $replace = array('o','o','u','o','u','e','a','u','i', 'O','U','O','O','U','E','A','U','I', '_', 'ss', 'a', 'Á', ''); $str = str_replace($search, $replace, $str); $forbidden_chars = '/(?!<.*?)(%s)(?![^<>]*?>)/i'; $str = preg_replace($forbidden_chars, '', $str); return $str; } }
The code only handle some languages from free text to URL safe text
Obviously this extension much more better. Thanks
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.