Php 正则表达式从Codeigniter中的url中排除类别。怎样
我想要 这些URL作为“我的页面”上的类别:Php 正则表达式从Codeigniter中的url中排除类别。怎样,php,codeigniter,Php,Codeigniter,我想要 这些URL作为“我的页面”上的类别: http://example.com/en/articles //for list of all http://example.com/en/articles/cars //for list of all cars articles http://example.com/en/articles/nature //for list of all nature acrticles http://example.com/en/arti
http://example.com/en/articles //for list of all
http://example.com/en/articles/cars //for list of all cars articles
http://example.com/en/articles/nature //for list of all nature acrticles
http://example.com/en/articles/sport //for list of all sport articles
我正在使用i18n,这就是为什么我还有其他链接,如:
http://example.com/fr/articles //for list of all
http://example.com/fr/articles/cars //for list of all cars articles
http://example.com/fr/articles/nature //for list of all nature acrticles
http://example.com/fr/articles/sport //for list of all sport articles
这很简单,我称之为controller articles.php,在它里面我有汽车、自然、运动等功能,一切都很好
但是,我希望有这样的文章,无论它们是什么类别:
$route[’^en/articles/(.+)$’] = “articles/show_full_article/$1”;
$route[’^fr/articles/(.+)$’] = “articles/show_full_article/$1”;
http://example.com/en/articles/article-about-nature
所以,当查看完整文章时,该类别从url中消失
我使用的是i18n,因此我的路线如下所示:
$route[’^en/articles/(.+)$’] = “articles/show_full_article/$1”;
$route[’^fr/articles/(.+)$’] = “articles/show_full_article/$1”;
但是每次调用函数时都会显示完整的文章,因为它位于第2部分
因此,我需要以某种方式重建正则表达式:
$route['^en/articles/(.+)$']=“articles/show_full_article/$1”
排除汽车、自然和运动的功能。我只有3个类别,所以手动输入没有什么大不了的
请,如果您知道如何在routes.php中键入regex来排除这三个类别,以便codeigniter不再将它们视为文章名,请告诉我。我将非常感激
提前感谢您的建议。您可能希望使用a来实现此目的。
就你而言:
$route['^en/articles/(?!(?:cars|nature|sport)$)(.+)$'] =
这样可以确保(.+)
不能是这些单词之一。它需要包装在(?:…)$
中,这样它也会匹配字符串的结尾,否则断言也会阻止natureSMTHNG
和类似的更长术语。可能重复的