__PRE__
工作得很好,但我发现了一些失败的案例:
gen_slug('Andrés Cortez')返回andres-cortez而不是gen_slug('Andrés Cortez')
为什么?关于andres-cortez参数的任何想法?
我正在尝试找到最好的方法(在可用性和性能方面)处理诸如获取标记有特定标记或类别或类似内容的记录之类的情况.
一个好方法(我想做的方式),是用标签/类别slug获取记录,所以URL看起来像:
http://stackoverflow.com/questions/tagged/language-agnostic
Run Code Online (Sandbox Code Playgroud)
通过slug获取记录,看起来比以下更好:
http://stackoverflow.com/questions/tag/789/language-agnostic
Run Code Online (Sandbox Code Playgroud)
通过ID获取并添加slug,因此它更适合搜索引擎.这个性能更好,因为通过整数ID获取数据会比字符串更快.(cmiiw)
现在,使用db模式:
posts post_to_tags tags
----- ------------ ----
id id id
title post_id name
content tag_id slug
... ...
Run Code Online (Sandbox Code Playgroud)
我做得对吗?是否存在我需要知道的陷阱或最佳实践以避免性能问题?(例如,标签不应超过10,000条记录,或标签slug不应超过n个字符,或其他)
提前致谢.
我有一个数据库,其中包含一个名为带有字段标题的歌曲的表.现在,如果我的网址是(xxx =歌曲的标题),则apache会默默地重定向到类似于:的页面.http://www.foo.com/songs/xxx/song.php?title=xxx
为了修饰URL我将空格转换为下划线(因为我知道某些浏览器显示%20而不是空格,而不是%20实际上%20user%20友好%20ya%20知道20%%20i%20mean).
如果标题包含空格和下划线(例如DJ_underscore fx)并且脚本将其转换DJ_underscore_fx为sql,则会出现问题:
select * from songs where songs.title=xxx
Run Code Online (Sandbox Code Playgroud)
找不到它.
这里的草图更具体:
name_of the song- >
name_of_the_song)<a
href="/songs/name_of_the_song">name_of_the_song</a>)/songs/name_of_the_son- >
/song.php?title=name_of_the_song)select * from songs where songs.title=name_of_the_song)OK你看,有一个在看起来像数据库的条目name_of_the_song,但name_of the song.
如何管理整体,以便我的URL保持清晰,标题字段不限于一定数量的值(可以有空格,下划线,破折号,以及任何东西)?