I need some help I wrote the following preg_replace The idea of the script is to get the name of the language from the domain name:
If I have
http://www.domainname.com/nl/this/is/a/test/index.asp < P> I want to strip the (nl) part of the domain name. I is a variable for Nl languages, so it may be: < / Li> Represents the above domain language directories ...
& lt ;? Php $ sitename = "http: //". $ _ Server ["SERVER_NAME"]; $ Pagename = $ _SERVER ["PHP_SELF"]. "This is / is / test"; $ Language = "\ / .. \ /"; $ Language1 = preg_replace ("/ $ language /", "$ 1", "$ pagename"); ? & Gt; - I'm only using scripts where I know that the language directory will be.
- The above script is also / / test / (is) from the url (which tells me that the script is greedy.
The best way to capture the language from the URL What will happen?
Can someone provide me some guidance?
Thanks
This is a script that uses the advice given below:
& lt ;? php $ mainurl = "http: //" $ _ SERVER ["SERVER_NAME"]; $ fullpname = $ _SERVER ["PHP_SELF"]; $ main language = preg_replace ('% ^ / (\ W +?) /.*$% ',' $ 1 ', $ _SERVER ["REQUEST_URI"]; $ Strippedpagename = preg_replace ("/ $ mainlanguag E \ // ", '$ 1', $ _SERVER [" REQUEST_URI "]) ?? & gt; & lt ;? php echo" full url: ". $ Mainurl? & Gt; & lt; br & gt; Lt ;? php echo "Full page name:". $ Fullpagename? & Gt;
& lt ;? php echo "language:". $ Keynote? & Gt; & lt; br & gt; & Lt ;? php echo "Page name no language:" $ strippedpagename? "Gt;
What exactly do I want, or what a more beautiful way
Something like this:
$ language = preg_replace ( '% ^ / (\ W +?) /) * $%', '$ 1', $ _SE RVER ["REQUEST_URI"])
Comments
Post a Comment