用变量修改字符串 [英] modify string with variables
问题描述
您好,
我已经建立了一个多语言网站。语言由url中的变量
定义 - > L = EN。网址中可能有更多变量:
mydomain.com/site.php?l=en&item=5&name=foo,但l = en也可以是
仅变量。
由于各种原因,请求的URL保存在会话变量中。
现在我想知道,如果有人输入的语言不是不匹配我提供的任何
语言,我希望将它们重定向到一个告诉
他们语言不存在的页面。
链接不允许丢失任何可能的变量,我试图通过搜索''l =''和''&''来使用
preg_replace,但是因为我不确定
是多个变量,所以URL中并不总是''&''。有什么线索吗?
谢谢。
Hi there,
i''ve built a multi-langual site. Languages are defined by a variable
in the url -> ''l=en''. There can be more variables in the url:
mydomain.com/site.php?l=en&item=5&name=foo, but l=en can also be the
only variable.
The requested url is saved in a session variable for various reasons.
Now i wonder, if someone enters a language that doesn''t match any
language i provided, i want them to be redirected to a page which tells
them the language doesn''t exist.
The links aren''t allowed to lose any possible variables, i tried to use
preg_replace by searching ''l='' and ''&'', but since i''m not sure there
are multiple variables, there isn''t always a ''&'' in the URL. Any clues?
thanks.
推荐答案
frizzle写道:
frizzle wrote:
你好,
我已经建立了一个多语言网站。语言由url中的变量
定义 - > L = EN。网址中可能有更多变量:
mydomain.com/site.php?l=en&item=5&name=foo,但l = en也可以是唯一的变量。 />
由于各种原因,请求的URL保存在会话变量中。
现在我想知道,如果有人输入的语言与我提供的任何语言都不匹配,我想要它们被重定向到一个页面,
告诉他们语言不存在。
链接不允许丢失任何可能的变量,我试图
使用preg_replace通过搜索''l =''和''&'',但由于我不确定
是多个变量,所以URL中并不总是''&'' 。任何
Hi there,
i''ve built a multi-langual site. Languages are defined by a variable
in the url -> ''l=en''. There can be more variables in the url:
mydomain.com/site.php?l=en&item=5&name=foo, but l=en can also be the
only variable.
The requested url is saved in a session variable for various reasons.
Now i wonder, if someone enters a language that doesn''t match any
language i provided, i want them to be redirected to a page which tells them the language doesn''t exist.
The links aren''t allowed to lose any possible variables, i tried to use preg_replace by searching ''l='' and ''&'', but since i''m not sure there
are multiple variables, there isn''t always a ''&'' in the URL. Any
线索?
当您的PHP由Web服务器启动时,超全局数组
clues?
When your PHP is started by the web server, the superglobal array
_GET
填充了在URL上输入的值。
在您的情况下,如果有''l = en'',那么将是一个
_GET
is filled with the values entered on the URL.
In your case, if there is a ''l=en'', then there will be a
_GET ['''']
,其值为''en''。
所以,设置一个包含所有允许语言的数组(对于
例如:
_GET[''l'']
with the value of ''en''.
So, set up an array containing all of the permissable languages (for
example:
这篇关于用变量修改字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!