从 url 获取变量,无法回显完整字符串
我有一个动态网址,如下所示;
news/categories/s/23-brook-launch-new-zealand
“23”是文章 ID,“brook-launch-new-zealand”是文章标题。
当我这样做时:
echo $_GET['title'];
它只会回显:“brook”而不是完整的字符串。
我正在对我的网址使用 mod_rewrite,代码如下:
RewriteRule ^news/categories/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+) /news/view-article.php?category=$1&id=$2&title=$3 [NC]
如何回显完整字符串?
I have a dynamic url which looks like the following;
news/categories/s/23-brook-launch-new-zealand
the "23" is the article id and the "brook-launch-new-zealand" is the article title.
When I do:
echo $_GET['title'];
it only echos back: "brook" not the full string.
I am using mod_rewrite for my urls, code follows:
RewriteRule ^news/categories/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+) /news/view-article.php?category=$1&id=$2&title=$3 [NC]
How can I echo the full string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您没有匹配可能的
-
:因此完整的行将是:
You aren't matching against possible
-
s:So the full line would be:
您的重写规则不支持破折号,请尝试以下一个:
Your rewrite rule does not support dashes try this one:
您用于匹配标题
([a-zA-Z]+)
的正则表达式仅匹配一组字母 (az),不包含破折号 (-) 符号。也许正则表达式的那部分应该是:
(([a-zA-Z]+-?)+)
那么你的重写规则将是:
The regex that you are using to match the title
([a-zA-Z]+)
only matches a set of leters (a-z) and does not include a dash (-
) symbol. Perhaps that part of the regular expression should be:(([a-zA-Z]+-?)+)
Then your rewrite rule would be:
我想你可能想要:
在你的版本中,标题中只允许使用字母 (a-zA-Z),因此正则表达式与破折号不匹配。上面的内容应该与破折号相匹配,并且还允许标题中出现数字(我怀疑您会希望允许)。
您甚至可能只想这样做:
...并允许标题中包含任何字符 - 您可以轻松摆脱这一点,因为标题是 URL 的最后部分。
I think you probably want:
With your version, only the letters (a-zA-Z) are allowed in a title, so the regex doesn't match the dashes. The above should match the dashes, and also will allow numbers in the title (which I suspect you will want to allow).
You may even simply want to do:
...and allow any character in the title - which you can easily get away with, since the title is the last portion of the URL.