0

i'm having a database which is storing geo-data like countries, cities. i would like to use modrewrite with links like: mysite.com/europe/austria/vienna

now the problem: in german, some countries contain umlauts like austria = österreich (i can't use umlauts in urls)

so my question: is there a way to create a function inside the database which replaces all special characters when querying like "where validUrl(country)='oesterreich' ? which would replace ö->oe

my only idea so far is adding an extra database field for modrewrite which would hold "oesterreich"

any ideas? thanks

4

2 回答 2

1

你可以像这样在 MySQL 中创建一个函数

DELIMITER $$

CREATE FUNCTION UmlautRaus(input varchar) RETURNS varchar
BEGIN
  declare output varchar;

  SET output = REPLACE(input,'ü','ue');
  SET output = REPLACE(output,.....
  ....
  RETURN output;
END $$

DELIMITER ;

然而,正如@GolezTrol 所说,这不是一个好主意,因为其他语言中的变音符号。

链接:http ://dev.mysql.com/doc/refman/5.1/en/string-functions.html

于 2011-05-16T23:08:44.557 回答
1

它对你没有帮助,因为虽然你可以用 ue 在德语中替换 ü,但你不能用其他语言的变音符号来做这样的事情。但是,您可以对这些字符进行编码,以便它们在 url 中有效。参见urlencode和 urldecode 。

此外,当您将列的排序规则设置为 unicode_ci 时,您应该能够选择相似的字符串,因此WHERE YourField = 'enquête'也应该匹配 'enquete'。'österreich' 可能会匹配 'osterreich' 但不会匹配 'oesterreich'。MySQL 可能不够聪明,无法知道这个词是法语还是德语。

您可以选择专门的德国排序规则,但这不适合您的目标。阅读有关排序规则的文本可能仍然很有趣,因为它显示了两个德国排序规则之间的差异。

于 2011-05-16T22:44:56.367 回答