Re: Newbie Question: How to pass URL info to .php script ?

From: Date: Thu, 19 Jun 2008 07:28:32 +0000
Subject: Re: Newbie Question: How to pass URL info to .php script ?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-275576@lists.php.net to get a copy of this message
Ethan, you can try this: $url = www.test.com/article/3435; echo basename($url); another solution is that you can use explode() function to seprate your url from '/' or you can use regex to parse your url - Jignesh On Thu, Jun 19, 2008 at 8:18 AM, Ethan Whitt <ethan.j.whitt@gmail.com> wrote: > I pasted your example in and it doesn't work for me (again, newbie). I > will > play with it and see if I can get it working. My main goal is to have > Ruby-like URL's vs "?var=3425". Is this possible with .php (without > mod_rewrite / something in the http server?) > Thanks, > > Ethan > > > > > On Wed, Jun 18, 2008 at 9:59 PM, Nathan Nobbe <quickshiftin@gmail.com> > wrote: > > > On Wed, Jun 18, 2008 at 10:45 PM, Ethan Whitt <ethan.j.whitt@gmail.com> > > wrote: > > > >> Not sure how to achieve this. How can I grab a portion of a URl to send > >> to > >> a .php script in this fashion? > >> > >> www.test.com/article/3435 <- Grab the "3435" to process in a script? > > > > > > take a look at the $_SERVER superglobal array, > > > > http://www.php.net/manual/en/reserved.variables.server.php > > > > most likely you are looking for, $_SERVER['PATH_TRANSLATED'], but it > really > > depends on what you want out of the url, so make sure to read through the > > options, and their explanations. those values are just strings, so its > > quite easy to extract portions of the string using a variety of > techniques. > > for example, give the url in your question (suppose we find it in > > $_SERVER['PATH_TRANSLATED']) > > > > $lastPath = substr($_SERVER['PATH_TRANSLATED'], > > strrpos($_SERVER['PATH_TRANSLATED']), '/') + 1); // $lastPath = > > '3435' > > > > -nathan > > >

« previous php.general (#275576) next »